class Container(containers.DeclarativeContainer):

    app = flask.Application(Flask, __name__)

    # Configuración
    config = providers.Configuration('config')

    # Dependencias
    logger = providers.Singleton(logging.Logger, name='logger')
    psycopg2_data_manager = providers.Singleton(Psycopg2DataManager,
                                                user=config.username,
                                                password=config.password,
                                                host=config.host,
                                                port=config.port,
                                                db_name=config.db_name)

    sqlalchemy_orm_data_manager = providers.Singleton(SqlAlchemyORMDataManager,
                                                      user=config.username,
                                                      password=config.password,
                                                      host=config.host,
                                                      port=config.port,
                                                      db_name=config.db_name)

    # Servicios
    gestor_pedidos = providers.Selector(
        config.data_handler,
        psycopg2=providers.Singleton(GestorPedidos, psycopg2_data_manager,
                                     logger),
        sqlalchemy=providers.Singleton(GestorPedidos,
                                       sqlalchemy_orm_data_manager, logger),
    )
Exemple #2
0
class Persistance(containers.DeclarativeContainer):
    """Application IoC container."""

    # Repositories
    portainer_repository = providers.Factory(PortainerRepository,
                                             Services.mongo_client)

    # Projections
    portainer_name_projection = providers.Singleton(
        PortainerNameProjection,
        Services.mongo_client,
        Services.domain_event_publisher,
    )
    portainer_check_time_projection = providers.Singleton(
        PortainerCheckTimeProjection,
        Services.mongo_client,
        Services.domain_event_publisher,
    )

    projections = [portainer_name_projection, portainer_check_time_projection]

    # Views
    portainer_name_view = providers.Factory(PortainerNameView,
                                            Services.mongo_client)
    portainer_check_time_view = providers.Factory(PortainerCheckTimeView,
                                                  Services.mongo_client)
Exemple #3
0
class Container(containers.DeclarativeContainer):
    config = providers.Configuration()

    logger = providers.Singleton(LoggingHandler, log_level=config.LOG_LEVEL)

    api_client = providers.Singleton(ApiClient, logger=logger)

    db_handler = providers.Singleton(DbHandler,
                                     logger=logger,
                                     mongo_uri=config.MONGO_URI,
                                     mongo_db_name=config.MONGO_DBNAME)

    bot = providers.Singleton(commands.Bot,
                              command_prefix=config.PREFIX,
                              help_command=None)

    main_cog = providers.Singleton(
        MainCog,
        logger=logger,
        discord_bot=bot,
        db_handler=db_handler,
        api_client=api_client,
    )

    service = providers.Factory(BotService,
                                logger=logger,
                                bot=bot,
                                main_cog=main_cog,
                                discord_token=config.DISCORD_TOKEN)
Exemple #4
0
class UtilityClientScopeProvider(containers.DeclarativeContainer):
    """IoC container of utilities providers."""

    database_client = providers.Singleton(DatabaseUtil)
    time_zone_client = providers.Singleton(TimeUtil)
    logging_client = providers.Singleton(LoggingUtil)
    network_client = providers.Singleton(NetworkUtil)
Exemple #5
0
class Container(containers.DeclarativeContainer):
    config_handler = providers.Singleton(
        ConfigHandler
    )

    telegram_client = providers.Singleton(
        MyTelegramClient,
        config_handler=config_handler
    )

    data_handler = providers.Factory(
        DataHandler,
        config_handler=config_handler
    )

    telegram_handler = providers.Factory(
        TelegramHandler,
        telegram_client=telegram_client
    )

    tracking_handler = providers.Factory(
        TrackingHandler,
        telegram_handler=telegram_handler,
        config_handler=config_handler,
        data_handler=data_handler
    )
def init():
    configs_factory.override(
        providers.Singleton(lambda: krules_settings)
    )

    proc_events_rx_factory.override(
        providers.Singleton(rx.subjects.ReplaySubject)
    )

    event_router_factory.override(
        providers.Singleton(lambda: EventRouter())
    )

    exceptions_dumpers = exceptions_dumpers_factory()
    exceptions_dumpers.set(ExceptionDumperBase)
    exceptions_dumpers.set(RequestsHTTPErrorDumper)

    # TODO: do it better
    source = None
    if "K_SERVICE" in os.environ:
        source = os.environ["K_SERVICE"]
    elif "SERVICE" in os.environ:
        source = os.environ["SERVICE"]
    else:
        source = socket.gethostname()

    from krules_cloudevents.route.dispatcher import CloudEventsDispatcher
    event_dispatcher_factory.override(
        providers.Singleton(lambda: CloudEventsDispatcher(krules_settings["CLOUDEVENTS"]["send_to"], source))
    )
Exemple #7
0
class FleaMarketContainer(containers.DeclarativeContainer):
    flea_config: Dependency[FleaMarketConfig] = providers.Dependency()
    templates_repository: Dependency[ItemTemplatesRepository] = providers.Dependency()
    globals_repository: Dependency[GlobalsRepository] = providers.Dependency()
    item_factory: Dependency[ItemFactory] = providers.Dependency()

    generator: providers.Provider[OfferGenerator] = providers.Singleton(
        OfferGenerator,
        config=flea_config,
        templates_repository=templates_repository,
        globals_repository=globals_repository,
        item_factory=item_factory,
    )

    view: providers.Provider[FleaMarketView] = providers.Factory(
        FleaMarketView,
        templates_repository=templates_repository,
    )

    market: providers.Provider[FleaMarket] = providers.Singleton(
        FleaMarket,
        offer_generator=generator,
        flea_view_factory=view.provider,
        flea_config=flea_config,
    )
Exemple #8
0
class ManagerProvider:
    cfg = providers.Singleton(Config, cfg=DATABASE)
    manager = providers.Singleton(ManagerInterface, cfg=cfg().cfg)()

    def get_processor(self, id_processor=None):
        try:
            print(self.manager.get_processor(id_processor))
        except lacksError:
            print('Processor does not exists.')

    def insert_new_processor(self, **kwargs):
        try:
            self.manager.insert_new_processor(**kwargs)
        except KeyError:
            print('Fields name and price are required!')

    def remove_processor(self, id_processor=None):
        try:
            self.manager.remove_processor(id_processor)
        except TypeError:
            print('Processor id has no exist.')

    def update_characteristics(self, id_processor=None, **kwargs):
        try:
            self.manager.update_characteristics(id_processor, **kwargs)
        except TypeError:
            print('Processor id has no exist.')
        except lacksError:
            print('Processor does not exists.')

    def get_count(self):
        print(self.cfg().count)
Exemple #9
0
def init():
    blackboard.account_cache = providers.Singleton(AccountCache,
                                                   db=blackboard.database)
    account_repository.provided_by(
        providers.Singleton(DbAccountRepository,
                            db=blackboard.database,
                            cache=blackboard.account_cache))
class Services(containers.DeclarativeContainer):
    config_loader = providers.Singleton(ConfigLoaderService)
    http = providers.Singleton(HttpService, Configs.http)
    pokemon = providers.Singleton(PokemonService,
                                  Configs.pokemon,
                                  http_service=http)
    s3 = providers.Singleton(S3Service, Configs.s3)
Exemple #11
0
class ManeuverResolvers(containers.DeclarativeContainer):
    config = providers.Configuration()
    managers = providers.DependenciesContainer()
    action_resolvers = providers.DependenciesContainer()
    logger = providers.Singleton(
        DirectNotify
    )

    passive_observation_resolver = providers.Singleton(
        PassiveObservationManeuverResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger,
        generic_resolver=action_resolvers.generic_action_resolver
    )

    movement_resolver = providers.Singleton(
        MoveManeuverResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger,
        generic_resolver=action_resolvers.generic_action_resolver
    )

    move_attack_resolver = providers.Singleton(
        MoveAttackManeuverResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger,
        generic_resolver=action_resolvers.generic_action_resolver
    )

    yield_turn_resolver = providers.Singleton(
        YieldTurnManeuverResolver,
        simulation_manager=managers.simulation_manager,
        logger=logger,
        generic_resolver=action_resolvers.generic_action_resolver
    )
class SchedulerDomain(containers.DeclarativeContainer):
    """IoC container of service providers."""
    inter_domain_event_bindings = providers.Object({
        strongr.core.domain.clouddomain.CloudDomain.events()['jobfinished']:
        {  # command / query generators based on event
            'command':
            [(lambda event: SchedulerDomain.commandFactory().newJobFinished(
                event.job_id, event.ret, event.retcode))  #,
             #(lambda event: SchedulerDomain.commandFactory().newRunEnqueuedJobs())
             ]
        },
        strongr.core.domain.clouddomain.CloudDomain.events()['vmnew']: {
            'command':
            [(lambda event: SchedulerDomain.commandFactory().newVmNew(
                event.vm_id, event.cores, event.ram))]
        },
        strongr.core.domain.clouddomain.CloudDomain.events()['vmcreated']: {
            'command': [(lambda event: SchedulerDomain.commandFactory().
                         newVmCreated(event.vm_id))]
        },
        strongr.core.domain.clouddomain.CloudDomain.events()['vmready']: {
            'command': [(lambda event: SchedulerDomain.commandFactory().
                         newVmReady(event.vm_id))]
        },
        strongr.core.domain.clouddomain.CloudDomain.events()['vmdestroyed']: {
            'command': [(lambda event: SchedulerDomain.commandFactory().
                         newVmDestroyed(event.vm_id))]
        }
    })

    schedulerService = providers.Singleton(SchedulerService,
                                           inter_domain_event_bindings())
    commandFactory = providers.Singleton(CommandFactory)
    queryFactory = providers.Singleton(QueryFactory)
Exemple #13
0
class Core(containers.DeclarativeContainer):
    """IoC container of core component providers."""
    config = providers.Configuration('config')

    inter_domain_events_publisher = providers.Singleton(EventsPublisher, 'InterDomain')

    command_router = providers.Singleton(CommandRouter)
Exemple #14
0
class Container(containers.DeclarativeContainer):
    # settings
    settings = providers.Configuration()

    # database
    db = providers.Singleton(Database, db_url=settings.DB_URL)

    # repository
    user_repository = providers.Singleton(OrmUserRepository,
                                          session_factory=db.provided.session)
    review_repository = providers.Singleton(
        OrmReviewRepository, session_factory=db.provided.session)
    wish_repository = providers.Singleton(OrmWishRepository,
                                          session_factory=db.provided.session)
    drink_repository = providers.Singleton(OrmDrinkRepository,
                                           session_factory=db.provided.session)

    # application service
    user_application_service = providers.Singleton(
        UserApplicationService, user_repository=user_repository)
    auth_application_service = providers.Singleton(
        AuthApplicationService,
        user_application_service=user_application_service,
        jwt_secret_key=settings.JWT_SECRET_KEY,
        jwt_algorithm=settings.JWT_ALGORITHM,
    )
    review_application_service = providers.Singleton(
        ReviewApplicationService, review_repository=review_repository)
    wish_application_service = providers.Singleton(
        WishApplicationService, wish_repository=wish_repository)
    drink_application_service = providers.Singleton(
        DrinkApplicationService, drink_repository=drink_repository)
class Container(containers.DeclarativeContainer):

    config = providers.Configuration(yaml_files=["config.yml"])

    movie = providers.Factory(entities.Movie)

    csv_finder = providers.Singleton(
        finders.CsvMovieFinder,
        movie_factory=movie.provider,
        path=config.finder.csv.path,
        delimiter=config.finder.csv.delimiter,
    )

    sqlite_finder = providers.Singleton(
        finders.SqliteMovieFinder,
        movie_factory=movie.provider,
        path=config.finder.sqlite.path,
    )

    finder = providers.Selector(
        config.finder.type,
        csv=csv_finder,
        sqlite=sqlite_finder,
    )

    lister = providers.Factory(
        listers.MovieLister,
        movie_finder=finder,
    )
Exemple #16
0
class ConfigContainer(containers.DeclarativeContainer):
    flea_market = providers.Singleton(
        config.FleaMarketConfig.load,
    )

    bot_generation = providers.Singleton(config.BotGenerationConfig.load)
    traders = providers.Singleton(config.TradersConfig.load)
Exemple #17
0
class FakeServices(containers.DeclarativeContainer):
    config = providers.Configuration("config")
    authentication = providers.Singleton(AuthenticationTestAdapter,
                                         config.user_id)
    permission = providers.Singleton(PermissionTestAdapter)
    database = providers.Singleton(DatabaseTestAdapter)
    event_store = providers.Singleton(EventStoreTestAdapter)
Exemple #18
0
class Containers(containers.DeclarativeContainer):
    config = providers.Configuration()

    logging = providers.Resource(
        logging.config.fileConfig,
        fname=os.path.join(os.getcwd(), "logging.ini")
    )

    # declare objects initialize

    trigger_factory = providers.Factory(TriggerFactory)

    sched_event_listener = providers.Factory(SchedulerEventListener)

    scheduler = providers.Singleton(
        ScheduleManager,
        config = config.sched_config,
        event_listener = sched_event_listener
    )

    custom_handler = providers.Singleton(
        ExampleSubscribeHandler,
        scheduler = scheduler,
        trigger_fac = trigger_factory
    )

    remote_service = providers.Singleton(
        SubscribeRpcService,
        scheduler = scheduler,
        subscribe_handler = custom_handler
    )
Exemple #19
0
class Repositories(containers.DeclarativeContainer):
    user_repo = providers.Singleton(UserRepository,
                                    database=Databases.database)
    physical_stats_repo = providers.Singleton(PhysicalStatsRepository,
                                              database=Databases.database)
    product_repo = providers.Singleton(ProductRepository,
                                       database=Databases.database)
Exemple #20
0
class ApplicationContainer(containers.DeclarativeContainer):

    config = providers.Configuration(ini_files=["config.ini"])

    sqlite = providers.Singleton(sqlite3.connect, config.database.dsn)

    s3 = providers.Singleton(
        boto3.client,
        service_name="s3",
        aws_access_key_id=config.aws.access_key_id,
        aws_secret_access_key=config.aws.secret_access_key,
    )

    user_package = providers.Container(
        UserContainer,
        database=sqlite,
    )

    photo_package = providers.Container(
        PhotoContainer,
        database=sqlite,
        file_storage=s3,
    )

    analytics_package = providers.Container(
        AnalyticsContainer,
        user_repository=user_package.user_repository,
        photo_repository=photo_package.photo_repository,
    )
Exemple #21
0
class Container(containers.DeclarativeContainer):
    config = providers.Configuration()
    movie: providers.Factory[entities.Movie] = providers.Factory(entities.Movie)

    csv_finder = providers.Singleton(
        finders.CsvMovieFinder,
        movie_factory=movie.provider,
        path=config.finder.csv.path,
        delimiter=config.finder.csv.delimiter,
    )

    sqlite_finder = providers.Singleton(
        finders.SqliteMovieFinder,
        movie_factory=movie.provider,
        path=config.finder.sqlite.path,
    )

    orm_sqlite_finder = providers.Singleton(
        finders.ORMSqliteFinder,
        movie_factory=movie.provider,
        path=config.finder.sqlite.path,
    )

    finder = providers.Selector(
        config.finder.type,
        csv=csv_finder,
        sqlite=sqlite_finder,
        orm_sqlite=orm_sqlite_finder,
    )

    lister = providers.Factory(listers.MovieLister, movie_finder=finder)
Exemple #22
0
class Core(containers.DeclarativeContainer):

    config = providers.Configuration('config')

    logger = providers.Singleton(logging.Logger, name='log')

    presence_logger = providers.Singleton(logging.Logger, name='presence_logger')
Exemple #23
0
class Container(containers.DeclarativeContainer):

    config = providers.Configuration()

    logging = providers.Resource(
        logging.basicConfig,
        stream=sys.stdout,
        level=config.log.level,
        format=config.log.format,
    )

    coloredlogs.install()

    sessions = providers.Singleton(session_storage.SessionStorage,
                                   config.telegram)

    configurator = providers.Singleton(Configurator, sessions)

    mqtt = providers.Singleton(Mosquitto, configurator, sessions, config.mqtt)

    startup = providers.Singleton(Startup, sessions, mqtt)

    dispatcher = providers.Factory(dispatcher.Dispatcher,
                                   dispatchables=providers.List(
                                       mqtt,
                                       startup,
                                   ))
Exemple #24
0
class Services(containers.DeclarativeContainer):
    user_service = providers.Singleton(UserService, Repositories.user_repo)
    physical_stats_service = providers.Singleton(
        PhysicalStatsService, Repositories.physical_stats_repo,
        Repositories.user_repo)
    product_service = providers.Singleton(ProductService,
                                          Repositories.product_repo)
Exemple #25
0
class FakeServicesOld(containers.DeclarativeContainer):
    config = providers.Configuration("config")
    authentication = providers.Singleton(AuthenticationTestAdapter,
                                         config.user_id)
    superuser = providers.Configuration("superuser")
    permission = providers.Singleton(PermissionTestAdapter, superuser)
    datastore = providers.Singleton(DatabaseTestAdapter,
                                    old_style_testing=True)
Exemple #26
0
class Services(containers.DeclarativeContainer):

    identity_scanner = providers.Singleton(DummyScanner, logger=Core.logger)

    presence_processor = providers.Singleton(FilePresenceProcessor, logger=Core.logger,
                                           presence_logger=Core.presence_logger,
                                           target=Core.config.target,
                                           max_disconnect_pings=Core.config.max_disconnect_pings)
Exemple #27
0
class Core(containers.DeclarativeContainer):
    """IoC container of core component providers."""

    config = providers.Configuration('config')

    logger = providers.Singleton(logging.Logger, name='application')

    loop = providers.Singleton(asyncio.get_event_loop)
Exemple #28
0
class HandlerInjector(containers.DeclarativeContainer):
    """
    Handler
    """
    FindUserQuery = providers.Singleton(
        FindUserQueryHandler, service=AppServicesInjector.user_finder)
    CreateUserCommand = providers.Singleton(
        CreateUserCommandHandler, service=AppServicesInjector.user_create)
Exemple #29
0
class RepositoryInjector(containers.DeclarativeContainer):
    """
    Repository
    """
    user_mng = providers.Singleton(UserSqlMngRepository,
                                   adapter=AdapterInjector.sql_alchemy)
    user_finder = providers.Singleton(UserSqlFinderRepository,
                                      adapter=AdapterInjector.sql_alchemy)
Exemple #30
0
 def create_basic_log_adapter(providers, name, extra=None):
     log_message_factory_provider = providers.DelegatedFactory(Message)
     logger = providers.Singleton(logging.getLogger, name=name)
     return providers.Singleton(
         BasicLogAdapter,
         logger,
         log_message_factory=log_message_factory_provider,
         extra=extra)