public void Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection) { serviceCollection.AddTransient <ContentController>(); serviceCollection.AddScoped <IItemFactory, ItemFactory>(); serviceCollection.AddScoped <IItemSearchFactory, ItemSearchFactory>(); serviceCollection.AddScoped <IContextProvider, ContextProvider>(); serviceCollection.AddSingleton <IModelAssemblyProvider, ModelAssemblyProvider>(); serviceCollection.AddSingleton <ISpawnProvider, SpawnProvider>(); serviceCollection.AddSingleton <ITemplateMapProvider, TemplateMapProvider>(); serviceCollection.AddScoped <ISearchResultsAdapter, SearchResultsAdapter>(); }
public static ISqlRepositoryBuilder AddSqlRepository(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action <SqlRepositoryOptions> configure) { services.Configure(configure); services.AddSingleton(typeof(OfaSchlupfer.Model.IExternalRepositoryModelType), typeof(SqlRepositoryModelType)); services.AddTransient(typeof(SqlRepositoryModel), typeof(SqlRepositoryImplementation)); return(new SqlRepositoryBuilder(services)); }
// method runs after Constructor is done in first run // parameter of type IServiceCollection is passed into this method // doesn't return anything public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services.AddDbContext <Models.ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:BilliardStoreProducts:ConnectionString"])); services.AddDbContext <Models.AppIdentityDbContext>(options => options.UseSqlServer(Configuration["Data:BilliardStoreIdentity:ConnectionString"])); services.AddIdentity <Microsoft.AspNetCore.Identity.IdentityUser, Microsoft.AspNetCore.Identity.IdentityRole>() .AddEntityFrameworkStores <BilliardStore.Models.AppIdentityDbContext>() .AddDefaultTokenProviders(); services.AddTransient <Models.IProductRepository, Models.EFProductRepository>(); services.AddScoped <Models.Cart>(sp => Models.SessionCart.GetCart(sp)); services.AddSingleton <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>(); services.AddTransient <Models.IOrderRepository, Models.EFOrderRepository>(); services.AddTransient <SendGrid.ISendGridClient>((s) => { return(new SendGrid.SendGridClient(Configuration.GetValue <string>("SendGrid:Key"))); }); services.AddTransient <Braintree.IBraintreeGateway>((s) => { return(new Braintree.BraintreeGateway( Configuration.GetValue <string>("Braintree:Environment"), Configuration.GetValue <string>("Braintree:MerchantId"), Configuration.GetValue <string>("Braintree:PublicKey"), Configuration.GetValue <string>("Braintree:PrivateKey"))); }); services.AddTransient <SmartyStreets.IClient <SmartyStreets.USStreetApi.Lookup> >((s) => { return(new SmartyStreets.ClientBuilder( Configuration.GetValue <string>("SmartyStreets:AuthId"), Configuration.GetValue <string>("SmartyStreets:AuthToken") ).BuildUsStreetApiClient()); }); services.AddMvc(); services.AddMemoryCache(); services.AddSession(); } // makes EFProductRepository take the place of IProductRepository in the code
public static void RegisterServices (Microsoft.Extensions.DependencyInjection.IServiceCollection services) { // Domain Bus //services.AddTransient // <Domain.Core.Bus.IEventBus, Bus.RabbitMQEventBusSimple>(); // Updated! services.AddSingleton <Domain.Core.Bus.IEventBus, Bus.RabbitMQEventBus>(sp => { Microsoft.Extensions.DependencyInjection.IServiceScopeFactory serviceScopeFactory = sp.GetRequiredService <Microsoft.Extensions.DependencyInjection.IServiceScopeFactory>(); return(new Bus.RabbitMQEventBus(sp.GetService <MediatR.IMediator>(), serviceScopeFactory)); }); // Application Service(s) services.AddTransient <Banking.Application.Interfaces.IAccountService, Banking.Application.Services.AccountService>(); // Data services.AddTransient <Banking.Data.Context.DatabaseContext>(); services.AddTransient <Banking.Domain.Interfaces.IAccountRepository, Banking.Data.Repositories.AccountRepository>(); }
public static void UseRavenDbWithInjectedDocumentStore(this SchedulerBuilder.PersistentStoreOptions options, Microsoft.Extensions.DependencyInjection.IServiceCollection services) { options.SetProperty(StdSchedulerFactory.PropertyJobStoreType, typeof(RavenJobStore).AssemblyQualifiedNameWithoutVersion()); services.AddSingleton <IJobStore, RavenJobStore>(); }
private static void ConfigureServices(IConfiguration configuration, Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services.Configure <AppSettings> (configuration.GetSection(nameof(AppSettings))); services.AddSingleton <PromotionEngine>(); services.AddScoped <IblActivePromotion, blActivePromotion>(); services.AddScoped <IblSkuIdPrice, blSkuIdPrice>(); }
public static IServiceCollection AddMongoDB(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action <MongoDBOptions> setupAction) { var mongoOptions = new MongoDBOptions(); setupAction(mongoOptions); return(services .AddSingleton(provider => mongoOptions) .AddMongoDB(new MongoDBConfiguration(mongoOptions))); }
public static void RegisterMongoClient(this Microsoft.Extensions.DependencyInjection.IServiceCollection servicesBuilder) { servicesBuilder.AddSingleton <IMongoClient, MongoClient>(s => { var uri = s.GetRequiredService <IConfiguration>().GetValue <string>("MongoUri"); var settings = MongoClientSettings.FromConnectionString(uri); return(new MongoClient(settings)); }); }
public static void RegisterMongoDbRepositories(this Microsoft.Extensions.DependencyInjection.IServiceCollection servicesBuilder) { servicesBuilder.AddSingleton <CustomerRepository>(s => { var mongoClient = s.GetRequiredService <IMongoClient>(); var databaseName = s.GetRequiredService <IConfiguration>().GetValue <string>("DatabaseName"); return(new CustomerRepository(mongoClient, databaseName)); }); //add additional repositories >>here<< }
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddUrlHelper(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services .AddSingleton <IActionContextAccessor, ActionContextAccessor>() .AddScoped(it => it .GetRequiredService <IUrlHelperFactory>() .GetUrlHelper(it.GetRequiredService <IActionContextAccessor>().ActionContext)); return(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services.AddOptions(); services.AddMvc(); services.AddCors(); services.AddOptions(); services.AddSingleton <IDictaatRepository, DictaatRepository>(); services.AddSingleton <IPageRepository, PageRepository>(); services.AddSingleton <IMenuRepository, MenuRepository>(); services.AddScoped <IQuestionRepository, QuestionRepository>(); services.AddSingleton <Core.IDirectory, Core.Directory>(); services.AddSingleton <Core.IFile, Core.File>(); services.Configure <ConfigVariables>(Configuration.GetSection("ConfigVariables")); var connection = @"Server = Stijn; Database = Webdictaat; Trusted_Connection = True; MultipleActiveResultSets=True"; services.AddDbContext <DomainContext>(options => options.UseSqlServer(connection), ServiceLifetime.Scoped); }
public static void AddRabbitMqHandler <T>(this IServiceCollection services, bool subscribeToQueue) where T : class { var sp = services.BuildServiceProvider(); var bus = sp.GetService <IBus>(); var repoLite = sp.GetService <IRabbitMqBackupLiteDbService>(); var repo = sp.GetService <IRabbitMqBackupService>(); var obj = (T)Activator.CreateInstance(typeof(T), services, bus, repo, repoLite, subscribeToQueue); services.AddSingleton(obj); }
} // End Constructor System.IServiceProvider UniversalService.IStartup .ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services.AddLogging(); // Inject common service services.AddSingleton(typeof(UniversalService.ICommonService), typeof(CommonSampleService)); // My configuration services.AddSingleton(new MyConfig()); services.Configure <SmtpConfig>( delegate(SmtpConfig config) { config.Server = "hello world"; return; } ); return(services.BuildServiceProvider()); }
// This method gets called by the runtime. // Use this method to add services to the container. public void ConfigureServices( Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services.Configure <ForwardedHeadersOptions>(options => { // TODO: Add configurable proxy list // options.KnownProxies.Add(IPAddress.Parse("10.0.0.100")); }); services.AddSingleton(new SqlService()); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services.AddControllers(); // 添加MVC服务 services.AddControllersWithViews(); // 注册服务 #region 依赖注入 #region 注册方法注解 // Singleton:单例服务,从当前服务容器中获取这个类型的实例永远是同一个实例; // Scoped:每个作用域生成周期内创建一个实例; // Transient:每一次请求服务都创建一个新实例; #endregion services.AddSingleton <ILogService, SysLogService>(); //services.AddScoped<ILogService, SysLogService>(); //services.AddTransient<ILogService, SysLogService>(); services.AddTransient <IOperationTransient, Operation>(); services.AddScoped <IOperationScoped, Operation>(); services.AddSingleton <IOperationSingleton, Operation>(); services.AddSingleton <IOperationSingletonInstance>(new Operation(Guid.Empty)); services.AddTransient <OperationService, OperationService>(); var serviceCollection = new ServiceCollection() .AddTransient <ILogService, SysLogService>() .AddSingleton <ILogService, SysLogService>() .AddScoped <ILogService, SysLogService>(); #endregion }
public void ConfigureRepositoryServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { //services.AddDbContext<SupplyOfProductsContext>(options => // options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection") //)); // Add Repositories. services.AddSingleton <IGenericContext, SupplyOfProductsContext>(); services.AddTransient <IProductRepository, ProductRepository>(); services.AddTransient <IProductSupplyRepository, ProductSupplyRepository>(); services.AddTransient <IWorkerRepository, WorkerRepository>(); services.AddTransient <IWorkerInWorkPlaceRepository, WorkerInWorkPlaceRepository>(); services.AddTransient <IWorkPlaceRepository, WorkPlaceRepository>(); services.AddTransient <IProductStockRepository, ProductStockRepository>(); services.AddTransient <ISupplyScheduledRepository, SupplyScheduledRepository>(); services.AddTransient <IConfigSupplyRepository, ConfigSupplyRepository>(); }
public static void ConfigMapper(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { // Auto Mapper Configurations var mappingConfig = new MapperConfiguration(mc => { var profileType = typeof(Profile); var allProfiles = typeof(SchoolProfile).Assembly.GetTypes() .Where(p => profileType.IsAssignableFrom(p) && !p.IsInterface && !p.IsAbstract) .Select(x => (Profile)Activator.CreateInstance(x)); foreach (var profileInstance in allProfiles) { mc.AddProfile(profileInstance); } }); IMapper mapper = mappingConfig.CreateMapper(); services.AddSingleton(mapper); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services.AddSingleton <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>(); services.AddSingleton <SearchValueTransformer>(); MyBlogCore.SqlFactory fac = CreateAppropriateFactory(); services.AddSingleton <MyBlogCore.SqlFactory>(fac); // This method configures the MVC services for the commonly used features with controllers with views. // This combines the effects of Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(Microsoft.Extensions.DependencyInjection.IServiceCollection), // Microsoft.Extensions.DependencyInjection.MvcApiExplorerMvcCoreBuilderExtensions.AddApiExplorer(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder), // Microsoft.Extensions.DependencyInjection.MvcCoreMvcCoreBuilderExtensions.AddAuthorization(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder), // Microsoft.Extensions.DependencyInjection.MvcCorsMvcCoreBuilderExtensions.AddCors(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder), // Microsoft.Extensions.DependencyInjection.MvcDataAnnotationsMvcCoreBuilderExtensions.AddDataAnnotations(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder), // Microsoft.Extensions.DependencyInjection.MvcCoreMvcCoreBuilderExtensions.AddFormatterMappings(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder), // Microsoft.Extensions.DependencyInjection.TagHelperServicesExtensions.AddCacheTagHelper(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder), // Microsoft.Extensions.DependencyInjection.MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder), // and Microsoft.Extensions.DependencyInjection.MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder). // To add services for pages call Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddRazorPages(Microsoft.Extensions.DependencyInjection.IServiceCollection) // services.AddControllersWithViews(); /// string cs = Configuration.GetConnectionString("DefaultConnection"); services.AddControllersWithViews( delegate(Microsoft.AspNetCore.Mvc.MvcOptions opts) { // opts.default } ).AddRazorRuntimeCompilation( delegate(Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.MvcRazorRuntimeCompilationOptions options) { // options.FileProviders.Clear(); options.FileProviders.Add(new DatabaseFileProvider(fac)); // https://github.com/aspnet/FileSystem/blob/master/src/FS.Embedded/EmbeddedFileProvider.cs // options.FileProviders.Add( new Microsoft.Extensions.FileProviders.EmbeddedFileProvider(typeof(Startup).Assembly) ); } ) ; // https://www.mikesdotnetting.com/article/301/loading-asp-net-core-mvc-views-from-a-database-or-other-location // https://stackoverflow.com/questions/38247080/using-razor-outside-of-mvc-in-net-core // https://github.com/dotnet/AspNetCore.Docs/issues/14593 //services.Configure<Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.MvcRazorRuntimeCompilationOptions>( // delegate(Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.MvcRazorRuntimeCompilationOptions options) // { // // Requires adding nuget Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation // // options.FileProviders.Clear(); // options.FileProviders.Add(new DatabaseFileProvider("cs")); // } //); services.AddOptions <Microsoft.AspNetCore.Builder.StaticFileOptions>() .Configure <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Hosting.IWebHostEnvironment>( delegate(Microsoft.AspNetCore.Builder.StaticFileOptions options, Microsoft.AspNetCore.Http.IHttpContextAccessor httpContext, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env) { options.FileProvider = new DomainSpecificFileProvider(httpContext, env); } ); } // End Sub ConfigureServices
protected override void OnLoadCustomService(Microsoft.Extensions.Hosting.HostBuilderContext builder, Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection) { serviceCollection.AddSingleton <IPackageProviderService>(packageProviderService); }
public static Microsoft.Extensions.DependencyInjection.IServiceCollection UseCache(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.Configuration.IConfiguration config) { services.Configure <CacheConfig>(config.GetSection("iRon.Cache")); services.AddSingleton(typeof(ICacheRepository <>), typeof(CacheRepository <>)); return(services); }
public void Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection) { serviceCollection.AddTransient <UnusedCouponsController>(); serviceCollection.AddSingleton <CouponsServiceProvider>(); }
// // Summary: // Adds a singleton service of the type specified in TService with an implementation // type specified in TImplementation using the factory specified in implementationFactory // to the specified Microsoft.Extensions.DependencyInjection.void. // // Parameters: // services: // The Microsoft.Extensions.DependencyInjection.void to add the service // to. // // implementationFactory: // The factory that creates the service. // // Type parameters: // TService: // The type of the service to add. // // TImplementation: // The type of the implementation to use. // // s: // A reference to this instance after the operation has completed. public void AddSingleton <TService, TImplementation>(Func <IServiceProvider, TImplementation> implementationFactory) where TService : class where TImplementation : class, TService { _serviceCollection.AddSingleton <TService, TImplementation>(implementationFactory); }
public void ConfigureRepositoryServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { Registration.Autofac(); services.AddSingleton <IMapper>(sp => Mapper.Instance); new PersistenceDDBB.StartupWeb(Configuration).ConfigureRepositoryServices(services); // add Services services.AddScoped <IPeriodConfigurationService, PeriodConfigurationService>(); services.AddScoped <IProductService, ProductService>(); services.AddScoped <IProductSupplyService, ProductSupplyService>(); services.AddScoped <IWorkerService, WorkerService>(); services.AddScoped <IProductStockService, ProductStockService>(); services.AddScoped <ISupplyScheduledService, SupplyScheduledService>(); services.AddScoped <IWorkPlaceService, WorkPlaceService>(); services.AddScoped <IWorkerInWorkPlaceService, WorkerInWorkPlaceService>(); services.AddScoped <IConfigSupplyService, ConfigSupplyService>(); /*Retrievers*/ services.AddScoped <IStep <IManagementModelRetrieverRequest <IWorker> >, RetrieverGeneric <IWorker, IWorkerService> >(); services.AddScoped <IStep <IManagementModelRetrieverRequest <IWorkPlace> >, RetrieverGeneric <IWorkPlace, IWorkPlaceService> >(); services.AddScoped <IStep <IManagementModelRetrieverRequest <IProduct> >, RetrieverGeneric <IProduct, IProductService> >(); services.AddScoped <IStep <IManagementModelRetrieverRequest <IProductStock> >, RetrieverGeneric <IProductStock, IProductStockService> >(); services.AddScoped <IStep <IManagementModelRetrieverRequest <IConfigSupply> >, RetrieverByWorkerGeneric <IConfigSupply, IConfigSupplyService> >(); services.AddScoped <IStep <IManagementModelRetrieverRequest <IProductSupply> >, RetrieverByWorkerGeneric <IProductSupply, IProductSupplyService> >(); // common steps in order to validate and complete the request services.AddScoped(sp => new CoRBuilder(sp).Get( new ValidateAndCompleteWorker(sp.GetService <IWorkerService>()), new ValidateAndCompleteProduct(sp.GetService <IProductService>()), new ValidateAndCompleteWorkPlace(sp.GetService <IWorkPlaceService>()), new ValidateAndCompleteWorkerInWorkPlace(sp.GetService <IWorkerInWorkPlaceService>()), new ValidateAndCompleteDatePeriod(sp.GetService <IPeriodConfigurationService>()) )); /*ProductSupply*/ services.AddScoped(sp => new CoRBuilder(sp).Get( new StepUnitOfWork <IManagementModelRequest <IProductSupply> >(sp.GetService <ICreateUoW>()) , new ValidateRequestAndComplete <IManagementModelRequest <IProductSupply> >(sp.GetService <IStep <IRequestMustBeCompleted> >()) , new ValidateWorkerCanBeSupplied(sp.GetService <IProductSupplyService>(), sp.GetService <ISupplyScheduledService>()) , new AssignProductToWorker(sp.GetService <IProductSupplyService>(), sp.GetService <IProductStockService>()) )); /*ConfigSupply*/ services.AddScoped(sp => { var helper = new CoRBuilder(sp); return(helper.Get( new StepUnitOfWork <IManagementModelRequest <IConfigSupply> >(helper.GetService <ICreateUoW>()) , new ValidateRequestAndComplete <IManagementModelRequest <IConfigSupply> >(helper.GetService <IStep <IRequestMustBeCompleted> >()) , new ValidateAndCompleteWorkerCanBeConfigured(helper.GetService <IProductSupplyService>(), helper.GetService <ISupplyScheduledService>()) , new ScheduleConfigurationToWorker(helper.GetService <ISupplyScheduledService>()) )); }); /*IWorkerInfo*/ services.AddScoped(sp => { var helper = new CoRBuilder(sp); return(helper.Get( new ValidateRequestAndComplete <IWorkerInfoRequest>(helper.GetService <IStep <IRequestMustBeCompleted> >()), new GenerateWorkerReport(helper.GetService <IWorkerInWorkPlaceService>(), helper.GetService <IProductSupplyService>()) )); }); /*IWorker*/ services.AddScoped(sp => { var helper = new CoRBuilder(sp); return(helper.Get( new StepUnitOfWork <IManagementModelRequest <IWorker> >(helper.GetService <ICreateUoW>()) , new StepSaveModel <IWorker>(helper.GetService <IWorkerService>()) )); }); /*IWorkPlace*/ services.AddScoped(sp => { var helper = new CoRBuilder(sp); return(helper.Get( new StepUnitOfWork <IManagementModelRequest <IWorkPlace> >(helper.GetService <ICreateUoW>()) , new StepSaveModel <IWorkPlace>(helper.GetService <IWorkPlaceService>()) )); }); /*IProduct*/ services.AddScoped(sp => { var helper = new CoRBuilder(sp); return(helper.Get( new StepUnitOfWork <IManagementModelRequest <IProduct> >(helper.GetService <ICreateUoW>()) , new StepSaveModel <IProduct>(helper.GetService <IProductService>()) )); }); /*IProductStock*/ services.AddScoped(sp => { var helper = new CoRBuilder(sp); return(helper.Get( new StepUnitOfWork <IManagementModelRequest <IProductStock> >(helper.GetService <ICreateUoW>()) , new ValidateRequestAndComplete <IManagementModelRequest <IProductStock> >(helper.GetService <IStep <IRequestMustBeCompleted> >()) , new StepSaveModel <IProductStock>(helper.GetService <IProductStockService>()) )); }); }