コード例 #1
0
        public static CRMHelperDictionary ConverterParaCRMHelperDictionary(CrmAPIOptions config)
        {
            var dicionario = new CRMHelperDictionary();

            config.Endpoints.ForEach(item => dicionario.Add(item.Chave, new CRMHelperUriDetail()
            {
                Url = item.Url, HttpMetodo = item.HttpMetodo
            }));
            return(dicionario);
        }
コード例 #2
0
        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>();
        }