Example #1
0
        public void Install(IServiceCollection services, IConfiguration configuration)
        {
            //TODO: Implementar Option Pattern
            var configDBOptions = new ConfigDBOptions();

            configuration.GetSection("ConnectionStrings").Bind(configDBOptions);
            services.AddScoped(typeof(IUnitOfWork), ctx => new DapperUnitOfWork(configDBOptions));

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             configuration.GetConnectionString("DefaultConnection")));
            services.AddDefaultIdentity <IdentityUser>()
            .AddEntityFrameworkStores <ApplicationDbContext>();
        }
        public void Install(IServiceCollection services, IConfiguration configuration)
        {
            var configDBOptions = new ConfigDBOptions();

            configuration.GetSection("ConnectionStrings").Bind(configDBOptions);

            var crmAPIOptions = new CrmAPIOptions();

            configuration.GetSection("ApiCrmOptions").Bind(crmAPIOptions);
            var mapeamentoUrls = ParaCRMHelper.ConverterParaCRMHelperDictionary(crmAPIOptions);

            //Via Option Pattern
            services.Configure <DBSettings>(configuration.GetSection(
                                                DBSettings.DBSettingsOptions));

            services.Configure <CrmApiSettings>(configuration.GetSection(
                                                    CrmApiSettings.CrmApiSettingsOptions));

            services.AddScoped(ctx => new DapperUnitOfWork(configDBOptions));
            services.AddScoped(ctx => new CRMHelperUnitOfWork(mapeamentoUrls, crmAPIOptions.ClientId, crmAPIOptions.Secret));
            services.AddTransient <ServiceResolver>(serviceProvider => key =>
            {
                switch (key)
                {
                case RepositorieTypesEnum.Dapper:
                    return(serviceProvider.GetService <DapperUnitOfWork>());

                case RepositorieTypesEnum.CRM:
                    return(serviceProvider.GetService <CRMHelperUnitOfWork>());

                default:
                    return(null);
                }
            });
            services.AddTransient <IProconRepository, ProconRepository>();
            services.AddTransient <ICrmRepository, CrmRepository>();
        }