// 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 void ConfigureServices (Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services.AddControllers(); services.AddDbContext <Banking.Data.Context.DatabaseContext>(options => { // UseSqlServer -> using Microsoft.EntityFrameworkCore; // GetConnectionString -> using Microsoft.Extensions.Configuration; options.UseSqlServer (Configuration.GetConnectionString("BankingConnectionString")); }); services.AddSwaggerGen(current => { current.SwaggerDoc(name: "v1", info: new Microsoft.OpenApi.Models.OpenApiInfo { Version = "v1", Title = "Banking Microservice", }); }); services.AddMediatR(handlerAssemblyMarkerTypes: typeof(Startup)); Infrastructure.IoC.DependencyContainer.RegisterServices(services: services); }
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>(); }
// 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.AddMvc(); // به کنترلرها تزریق کنیم، به این دستور نیاز داریم DatabaseContext در صورتی که بخواهیم services.AddDbContext <Models.DatabaseContext>(options => options.UseSqlServer(Configuration.GetConnectionString(name: "DatabaseContext"))); }
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.Configure <FormOptions>(o => { o.ValueLengthLimit = int.MaxValue; o.MultipartBodyLengthLimit = int.MaxValue; o.MemoryBufferThreshold = int.MaxValue; }); services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("MSSQL"))); services.AddIdentity <ApplicationUser, IdentityRole>(cfg => { cfg.User.RequireUniqueEmail = true; }) .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddCookie() .AddJwtBearer(cfg => { cfg.TokenValidationParameters = new TokenValidationParameters() { ValidIssuer = this.Configuration["Tokens:Issuer"], ValidAudience = this.Configuration["Tokens:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(this.Configuration["Tokens:Key"])) }; }); services.Configure <IdentityOptions>(options => { options.Password.RequiredLength = 3; options.Password.RequireDigit = false; options.Password.RequireLowercase = false; options.Password.RequireUppercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequiredUniqueChars = 0; }); services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.WithOrigins("http://www.taximiapi.com.aspbg.net/", "http://localhost:8100/") .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials() .SetIsOriginAllowed((host) => true)); }); services.AddMvc(); services.AddSignalR(); services.AddControllers() .AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); services.RegisterRepositoryServices(); services.RegisterCloudinary(Configuration); services.Configure <MailSettings>(Configuration.GetSection("MailSettings")); services.RegisterCustomServices(); }
public static void ConfigureServices(IConfigurationRoot configurationRoot, Microsoft.Extensions.DependencyInjection.IServiceCollection services, ILogger logger) { var billingDbSection = configurationRoot.GetSection("BillingDb"); if (billingDbSection == null) { logger.AddCustomEvent(LogLevel.ConfigurationError, "BillingManager_Startup", "Missing Section BillingDb"); throw new InvalidConfigurationException(new IoT.Logging.Error() { ErrorCode = "CFG9991", Message = "Missing Section BillingDb" }); } var connectionSettings = new ConnectionSettings() { Uri = billingDbSection["ServerURL"], ResourceName = billingDbSection["InitialCatalog"], UserName = billingDbSection["UserName"], Password = billingDbSection["Password"], }; if (string.IsNullOrEmpty(connectionSettings.Uri)) { logger.AddCustomEvent(LogLevel.ConfigurationError, "BillingManager_Startup", "Missing BillingDb__ServerURL"); throw new InvalidConfigurationException(new IoT.Logging.Error() { ErrorCode = "CFG9999", Message = "Missing BillingDb__ServerURL" }); } if (string.IsNullOrEmpty(connectionSettings.ResourceName)) { logger.AddCustomEvent(LogLevel.ConfigurationError, "BillingManager_Startup", "Missing BillingDb__InitialCatalog"); throw new InvalidConfigurationException(new IoT.Logging.Error() { ErrorCode = "CFG9999", Message = "Missing BillingDb__InitialCatalog" }); } if (string.IsNullOrEmpty(connectionSettings.UserName)) { logger.AddCustomEvent(LogLevel.ConfigurationError, "BillingManager_Startup", "Missing BillingDb__UserName"); throw new InvalidConfigurationException(new IoT.Logging.Error() { ErrorCode = "CFG9999", Message = "Missing BillingDb__UserName" }); } if (string.IsNullOrEmpty(connectionSettings.Password)) { logger.AddCustomEvent(LogLevel.ConfigurationError, "BillingManager_Startup", "Missing BillingDb__Password"); throw new InvalidConfigurationException(new IoT.Logging.Error() { ErrorCode = "CFG9999", Message = "Missing BillingDb__Password" }); } var connectionString = $"Server=tcp:{connectionSettings.Uri},1433;Initial Catalog={connectionSettings.ResourceName};Persist Security Info=False;User ID={connectionSettings.UserName};Password={connectionSettings.Password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"; services.AddTransient <ISubscriptionRepo, SubscriptionRepo>(); services.AddTransient <IRDBMSManager, RDBMSManager>(); services.AddDbContext <UserAdminDataContext>(options => options.UseSqlServer(connectionString, moreOptions => moreOptions.EnableRetryOnFailure())); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { var cadena = Configuration.GetConnectionString("DefaultConnection"); services.AddDbContext <GeneralContext>(opt => opt.UseSqlServer(cadena, b => b.MigrationsAssembly("Verduras"))); services.AddControllersWithViews(); #region configure strongly typed settings objects var appSettingsSection = Configuration.GetSection("AppSetting"); services.Configure <AppSetting>(appSettingsSection); #endregion #region Configure jwt authentication inteprete el token var appSettings = appSettingsSection.Get <AppSetting>(); var key = Encoding.ASCII.GetBytes(appSettings.Secret); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = false, ValidateAudience = false }; } ); #endregion //Agregar OpenApi Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "School API", Description = "School API - ASP.NET Core Web API", TermsOfService = new Uri("https://cla.dotnetfoundation.org/"), Contact = new OpenApiContact { Name = "Unicesar", Email = string.Empty, Url = new Uri("https://github.com/borisgr04/CrudNgDotNetCore3"), }, License = new OpenApiLicense { Name = "Licencia dotnet foundation", Url = new Uri("https://www.byasystems.co/license"), } }); }); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }