// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // configure strongly typed settings objects from appsettings.json file var appSettingsSection = Configuration.GetSection("AppSettings"); services.Configure <AppSettings>(appSettingsSection); // configure DB services.AddDbContext <NebulaChatDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); // configure cors services.AddCors(options => options.AddPolicy("NebulaChatCorsPolicy", builder => { builder.AllowAnyMethod().AllowAnyHeader() .WithOrigins(appSettingsSection.Get <AppSettings>().ClientUrl) .AllowCredentials(); })); // configure jwt authentication JwtAuthConfiguration.Configure(services, appSettingsSection); services.AddAutoMapper(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSignalR(options => options.EnableDetailedErrors = true); // Set dependency injection DependencyInjectionConfiguration.Configure(services); }
public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); DependencyInjectionConfiguration.Configure(services); Log.Logger = new LoggerConfiguration() .MinimumLevel.Information() .WriteTo.Console() .WriteTo.File( "logs/log.txt", rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true) .CreateLogger(); }
public void ConfigureServices(IServiceCollection services) { BindConfiguration(services); CorsConfiguration.Configure(services); IMvcBuilder mvcBuilder = services .AddAutoMapper() .AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); JsonFormattingConfiguration.Configure(mvcBuilder); DependencyInjectionConfiguration.Configure(services); SwaggerConfiguration.Configure(services); }
private static void Main() { // configure IoC var dependencyInjectionConfiguration = new DependencyInjectionConfiguration(DependencyInjection.Container); dependencyInjectionConfiguration.Configure(); // some client logic var client = new SimpleClient(DependencyInjection.Container.Resolve <ApplesProvider>()); client.ShowApples(); // wait for key press Console.ReadKey(); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddDbContext <MatchOrganizerContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("Database")); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1).AddControllersAsServices().AddFluentValidation(); services.AddTransient <IValidator <CreateMatchViewModel>, CreateMatchValidator>(); return(DependencyInjectionConfiguration.Configure(services)); }
public IServiceProvider ConfigureServices(IServiceCollection services) { services.EnableSwagger(); services.AddMvc(opts => opts.Filters.Add(new ValidateModelStateAttribute())) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddHttpClient(); services.EnableCors(); services.EnableOptions(Configuration); services.EnableDatabase(Configuration); services.EnableIdentity(); services.EnableAuth(Configuration); services.EnableMapping(); services.EnableRabbitMq(Configuration); services.EnableDistrubutedMemoryCache(Configuration); services.EnableSchedulableJobs(Configuration); return(DependencyInjectionConfiguration.Configure(services)); }
public void Initialize(IUnityContainer container) { dependencyInjectionConfiguration = new DependencyInjectionConfiguration(container); dependencyInjectionConfiguration.Configure(); }
private void InitializeDependencyInjection() { dependencyInjectionConfiguration = new DependencyInjectionConfiguration(DependencyInjection.Container); dependencyInjectionConfiguration.Configure(); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddDbContext <OrhedgeContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("Database")); }); services.AddLocalization(options => options.ResourcesPath = "Resources"); services .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(opts => { opts.Cookie.IsEssential = true; opts.LoginPath = "/Home/Login"; opts.AccessDeniedPath = "/Home/AccessDenied"; opts.SlidingExpiration = true; opts.ExpireTimeSpan = TimeSpan.FromMinutes(30); opts.Events.OnRedirectToLogin = async ctx => { bool apiCall = ctx.Request.Path.StartsWithSegments("/api"); if (apiCall) { ctx.Response.StatusCode = StatusCodes.Status401Unauthorized; } else { ctx.Response.Redirect(ctx.RedirectUri); } await Task.CompletedTask; }; opts.Events.OnRedirectToAccessDenied = async ctx => { bool apiCall = ctx.Request.Path.StartsWithSegments("/api"); if (apiCall) { ctx.Response.StatusCode = StatusCodes.Status403Forbidden; } else { ctx.Response.Redirect(ctx.RedirectUri); } await Task.CompletedTask; }; }); services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddControllersAsServices() .AddViewLocalization() .AddDataAnnotationsLocalization( opts => opts.DataAnnotationLocalizerProvider = (type, factory) => factory.Create(typeof(SharedResource))); services.AddSignalR(); return(DependencyInjectionConfiguration.Configure(services)); }