public static void RegisterServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services, IConfiguration configuration) { services.AddDbContext <dbBuildTicketContext>(options => options.UseSqlServer(configuration.GetConnectionString("DevConnection"))); services.AddScoped <ITicketDomain, TicketDomain>(); services.AddScoped <IBuildRepository, BuildRepository>(); services.AddScoped <IBuildTicketService, BuildTicketService>(); }
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 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>(); }
// 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.AddAuthentication("Bearer") .DSAddJwtBearer(options => { options.AudienceAuthorityResolver = new CognitoUserPoolResolver(new DataContext()); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddScoped <IIAASService, AWSCognitoService>(); services.AddScoped <DataContext>(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { // Add Entity Framework services to the services container. services.AddEntityFramework() .AddSqlServer() .AddDbContext <PhotoGalleryContext>(options => options.UseSqlServer(Configuration["Data:PhotoGalleryConnection:ConnectionString"])); // Repositories services.AddScoped <IPhotoRepository, PhotoRepository>(); services.AddScoped <IAlbumRepository, AlbumRepository>(); services.AddScoped <IUserRepository, UserRepository>(); services.AddScoped <IUserRoleRepository, UserRoleRepository>(); services.AddScoped <IRoleRepository, RoleRepository>(); services.AddScoped <ILoggingRepository, LoggingRepository>(); // Services services.AddScoped <IMembershipService, MembershipService>(); services.AddScoped <IEncryptionService, EncryptionService>(); services.AddAuthentication(); // Polices services.AddAuthorization(options => { // inline policies options.AddPolicy("AdminOnly", policy => { policy.RequireClaim(ClaimTypes.Role, "Admin"); }); }); // Add MVC services to the services container. services.AddMvc(); }
// 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 IServiceCollection AddInfrastructure(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, IConfiguration configuration) { if (configuration.GetValue <bool>("UseInMemoryDatabase")) { services.AddDbContext <ApplicationDbContext>(options => options.UseInMemoryDatabase("CleanArchitectureDb")); } else { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName))); } services.AddScoped <IApplicationDbContext>(provider => provider.GetService <ApplicationDbContext>()); 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); }
// 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 ConfigureServices (Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services.AddCors(); services.AddControllers(); // Configure strongly typed settings object services.Configure <Infrastructure.ApplicationSettings.Main> (Configuration.GetSection("AppSettings")); // Configure Swagger for application services services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Version = "v1", Title = "Swagger Demo", Description = "Swagger Demo", TermsOfService = new System.Uri("https://example.com/terms"), Contact = new Microsoft.OpenApi.Models.OpenApiContact() { Name = "Mohsen Farokhi", Email = "*****@*****.**", Url = new System.Uri("https://www.linkedin.com/in/mohsen-farokhi"), }, License = new Microsoft.OpenApi.Models.OpenApiLicense { Name = "Use under LICX", Url = new System.Uri("https://example.com/license"), } }); c.AddSecurityDefinition("Bearer", new Microsoft.OpenApi.Models.OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme.", Name = "Authorization", In = Microsoft.OpenApi.Models.ParameterLocation.Header, Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey, Scheme = "Bearer" }); c.AddSecurityRequirement(new Microsoft.OpenApi.Models.OpenApiSecurityRequirement() { { new Microsoft.OpenApi.Models.OpenApiSecurityScheme { Reference = new Microsoft.OpenApi.Models.OpenApiReference { Type = Microsoft.OpenApi.Models.ReferenceType.SecurityScheme, Id = "Bearer" }, Scheme = "oauth2", Name = "Bearer", In = Microsoft.OpenApi.Models.ParameterLocation.Header, }, new System.Collections.Generic.List <string>() } }); var xmlPath = System.IO.Path.Combine(System.AppContext.BaseDirectory, "Application.xml"); c.IncludeXmlComments(xmlPath); }); // Configure DI for application services services.AddScoped <Services.IUserService, Services.UserService>(); }
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSoftmakeBlazorLocalStorage(this Microsoft.Extensions.DependencyInjection.IServiceCollection Services) => Services .AddScoped <SoftmakeAll.SDK.Blazor.ClientStorage.Services.IAsyncLocalStorageService, SoftmakeAll.SDK.Blazor.ClientStorage.Services.LocalStorageService>() .AddScoped <SoftmakeAll.SDK.Blazor.ClientStorage.Services.ISyncLocalStorageService, SoftmakeAll.SDK.Blazor.ClientStorage.Services.LocalStorageService>();
public void AddScoped <TService>() where TService : class { _serviceCollection.AddScoped <TService>(); }
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>()) )); }); }