def bind_databases(binder: Binder) -> Binder: application = binder.injector.get(Flask) metadata = MetaData() try: department_mapping(metadata) province_mapping(metadata) district_mapping(metadata) user_mapping(metadata) except Exception as e: # nosec, pylint: disable=broad-except print(e) db = SQLAlchemy(application) metadata.reflect(db.engine) metadata.drop_all(db.engine) db.session.commit() metadata.create_all(db.engine) db.session.commit() seed_data(db) binder.bind(SQLAlchemy, to=db, scope=singleton) return binder
def _inject_redis(binder: Binder) -> None: binder.bind( Storage, # Here we can inject different Storage subclasses, we can also use a Storage factory Redis(flask_app.config['STORAGE_HOST'], flask_app.config['STORAGE_PORT']), )
def core(binder: Binder): binder.bind(CommandBus, to=lambda: LocalSynchronousCommandBus(), scope=SingletonScope) binder.bind(EventBus, to=lambda: LocalSynchronousEventBus(), scope=SingletonScope)
def configure(self, binder: Binder) -> None: neo4j_storage = Neo4jStorage(hostname=self.config.NEO4J_HOSTNAME, port=self.config.NEO4J_PORT, username=self.config.NEO4J_LOGIN, password=self.config.NEO4J_PASSWORD) binder.bind(interface=Storage, to=neo4j_storage, scope=singleton) binder.bind(interface=CategoryDAO, to=Neo4jCategoryDAO, scope=singleton)
def configure_binding(binder: Binder) -> Binder: binder.bind(GetUserProfileUseCase, to=GetUserProfileUseCase, scope=singleton) # binder.bind(ProfileRepository, to=MockProfileRepository, scope=singleton) binder.bind(ProfileRepository, to=SqlProfileRepository, scope=singleton) return binder
def configure(binder: Binder): IocManager.binder = binder for config in IocManager.config_manager.get_all(): binder.bind( config.get("type"), to=config.get("instance"), scope=singleton, ) for singletonScope in ISingleton.__subclasses__(): binder.bind( singletonScope, to=singletonScope, scope=singleton, ) for scoped in IScoped.__subclasses__(): binder.bind( scoped, to=scoped, scope=threadlocal, ) for controller in ResourceBase.__subclasses__(): binder.bind( controller, to=controller, scope=request, ) if IocManager.app_wrapper is not None: api_config = IocManager.config_manager.get(ApiConfig) binder.bind(IocManager.app_wrapper, to=IocManager.app_wrapper(api_config))
def _configure_quotes_storer(binder: Binder, settings: LazySettings): from core.utils.download_data.quotes.boursorama import QuotationDownloader binder.bind( QuotationDownloader.Configuration, QuotationDownloader.Configuration( quotes_json_folder=settings.QUOTES_FOLDER_PATH), )
def _configure_crypto_quots(binder: Binder, settings: LazySettings): from crypto.services.repositories.quote_pair import QuotesPairRepository binder.bind( QuotesPairRepository.Configuration, QuotesPairRepository.Configuration( file_folder_path=settings.CRYPTO_QUOTES_FOLDER), )
def _configure_company_storer(binder: Binder, settings: LazySettings): from core.utils.store_data.companies import CompanyImporter binder.bind( CompanyImporter.Configuration, CompanyImporter.Configuration( companies_json_path=settings.COMPANIES_JSON_PATH), )
def __configure(binder: Binder) -> None: binder.bind(AbstractFileRepository, to=file_repository, scope=singleton) binder.bind(AbstractEnvironment, to=Environment, scope=singleton) binder.bind(AbstractLogger, to=Logger, scope=singleton) binder.bind(AbstractSpotifyClient, to=SpotifyClient, scope=singleton) binder.bind(AbstractJqbxClient, to=JqbxClient, scope=singleton)
def configure(binder: Binder) -> Binder: binder.bind( elasticSearchIndex, elasticSearchIndex( elasticSearchFactory(os.environ['ELASTICSEARCH_HOST'], os.environ['ELASTICSEARCH_PORT']), 'rooms', 'room', room_mapping)) return binder
def _configure_data_downloader(binder: Binder, settings: LazySettings): from core.utils.driver_manager.driver import DriverManager binder.bind( DriverManager.Configuration, DriverManager.Configuration( download_path=settings.DOWNLOAD_STOCKS_PATH, driver_path=settings.CHROME_DRIVER_PATH, ), )
def configure(binder: Binder) -> Binder: binder.bind( ElasticSearchIndex, ElasticSearchIndex( ElasticSearchFactory( config('ELASTICSEARCH_HOST'), config('ELASTICSEARCH_PORT'), ), 'rooms', 'room', room_mapping)) return binder
def configure(binder: Binder) -> Binder: binder.bind( ElasticSearchIndex, ElasticSearchIndex( ElasticSearchFactory( os.environ['ELASTICSEARCH_HOST'], os.environ['ELASTICSEARCH_PORT'], ), 'rooms_index', 'room', {})) return binder
def configure(self, binder: injector.Binder) -> None: for pm, handler_cls in self.PM_HANDLERS: handled_events = [ event for event in pm.handle.registry.keys() if issubclass(event, Event) ] for event in handled_events: binder.multibind(AsyncHandler[event], to=AsyncEventHandlerProvider(handler_cls)) return None
def configure(binder: Binder) -> Binder: binder.bind( ItemsProvider, ItemsProvider([{ "Name": "Test1" }]), ElasticSearchIndex, ElasticSearchIndex( ElasticSearchFactory(os.environ['ELASTICSEARCH_HOST'], os.environ['ELASTICSEARCH_PORT']), 'rooms', 'room', room_mapping)) return binder
def configure(binder: Binder) -> Binder: binder.bind( IfElseEngine, IfElseEngine({ 'crash': 0.6, 'died': 0.7, 'married': 0.76, 'funeral': 0.8 })) return binder
def configure(self, binder: Binder) -> None: binder.bind(Pool, connection_pool, scope=SingletonScope) binder.bind(SampleRepository, SampleDbRepositoryImpl, scope=SingletonScope) binder.bind(UserRepository, UserDbRepositoryImpl, scope=SingletonScope) binder.bind(SessionRepository, SessionDbRepositoryImpl, scope=SingletonScope) binder.bind(AppointmentRepository, AppointmentRepositoryImpl, scope=SingletonScope)
def configure(binder: Binder) -> Binder: """ Sets DI configurations """ config = get_config() provider_factory = CryptoProviderFactory(config) binder.bind( CryptoProService, to=CryptoProService(provider_factory, config), ) return binder
def configure_services(binder: Binder) -> Binder: binder.bind(ItemsProvider, to=ItemsProvider([{ "Name": "Test 1" }, { "Name": "Test 2" }, { "Name": "Test 3" }, { "Name": "Test 4" }, { "Name": "Test 5" }])) return binder
def configure(self, binder: Binder) -> None: super().configure(binder) binder.bind(BaseRunner, to=WatchdogRunner) binder.bind(CheckableObserver, to=SnapshotObserver) binder.bind(FileSystemEventHandler, to=SnapshotEventHandler) binder.bind(BaseLoggerFactory, to=SystemdLoggerFactory)
def configure(binder: Binder) -> Binder: binder.bind( ElasticSearchIndex, ElasticSearchIndex( ElasticSearchFactory( #os.environ['ELASTICSEARCH_HOST'], #os.environ['ELASTICSEARCH_PORT'], '127.0.0.1', 9200), 'rooms', 'room', room_mapping)) return binder
def configure(self, binder: Binder): binder.bind(ImageAcquisitionService, to=ImageAcquisitionService, scope=singleton) binder.bind(PendantPhysicalParamsFactory, scope=singleton) binder.bind(PendantFeaturesParamsFactory, scope=singleton) binder.bind(PendantFeaturesService, scope=singleton) binder.bind(YoungLaplaceFitService, scope=singleton) binder.bind(PendantAnalysisService, scope=singleton) binder.bind(IFTSession, to=IFTSession, scope=singleton)
def configure(self, binder: Binder) -> None: # Starting with Injector 0.13.2 explicit scope binding is no longer # necessary if injector_version < '0.13.2': binder.bind_scope(self.request_scope_class) binder.bind(flask.Flask, to=self.app, scope=singleton) binder.bind(Config, to=self.app.config, scope=singleton) binder.bind(Request, to=lambda: flask.request)
def configure(self, binder: Binder) -> None: binder.bind(interface=SwaggerService, to=SwaggerServiceImpl, scope=singleton) binder.bind(interface=UrlService, to=UrlServiceImpl, scope=singleton) binder.bind(interface=HeaderService, to=HeaderServiceImpl, scope=singleton) binder.bind(interface=BodyService, to=BodyServiceImpl, scope=singleton)
def configure(self, binder: Binder) -> None: billpay_private_client = BillpayClient( self._app.config.get('BILLPAY_MERCHANT_ID'), self._app.config.get('BILLPAY_PRIVATE_PORTAL_ID'), self._app.config.get('BILLPAY_PRIVATE_PASSWORD_HASH'), self._app.config.get('BILLPAY_API_URL')) billpay_business_client = BillpayClient( self._app.config.get('BILLPAY_MERCHANT_ID'), self._app.config.get('BILLPAY_BUSINESS_PORTAL_ID'), self._app.config.get('BILLPAY_BUSINESS_PASSWORD_HASH'), self._app.config.get('BILLPAY_API_URL')) billpay_provider = BillpayProvider(billpay_private_client, billpay_business_client) binder.bind(BillpayProvider, to=billpay_provider, scope=singleton)
def configure_database_bindings(binder: Binder) -> Binder: application = binder.injector.get(Flask) metadata = MetaData() try: user_mapping(metadata) except Exception: pass db = SQLAlchemy(application) metadata.reflect(db.engine) metadata.drop_all(db.engine) db.session.commit() metadata.create_all(db.engine) db.session.commit() binder.bind(SQLAlchemy, to=db, scope=singleton) return binder
def configure(self, binder: Binder) -> None: injector = binder.injector binder.bind( interface=Config, to=Config(), scope=singleton ) config = injector.get(Config) binder.bind( interface=Logger, to=self.__logger(config), scope=singleton ) binder.bind( interface=KafkaAdminClient, to=KafkaAdminClient( bootstrap_servers=f'{config.kafka_host}:{config.kafka_port}', client_id=config.app_name ), scope=singleton ) binder.bind( interface=KafkaProducer, to=KafkaProducer( client_id=config.app_name, bootstrap_servers=[f'{config.kafka_host}:{config.kafka_port}'] ), scope=singleton ) binder.bind( interface=KafkaConsumer, to=KafkaConsumer( config.kafka_oscillograms_topic_name, group_id=config.app_name, bootstrap_servers=[f'{config.kafka_host}:{config.kafka_port}'], enable_auto_commit=True ), scope=singleton )
def configure(binder: Binder) -> None: binder.bind(str, to=provide_str)
def configure(self, binder: Binder) -> None: binder.bind(flask.Flask, to=self.app, scope=singleton) binder.bind(Config, to=self.app.config, scope=singleton) binder.bind(Request, to=lambda: flask.request)
def configure(binder: Binder) -> Binder: binder.bind(ItemsProvider, ItemsProvider([{ 'Name': 'Test 1' }, { 'Name': 'Test 2' }]))
def configure(binder: Binder): def get_count(): global count count = count + 1 return count binder.bind(Count, to=CallableProvider(get_count), scope=flask_injector.request) binder.bind(MessageGenerator, to=MessageGenerator(message='hi there {}!'.format(text)))