示例#1
0
        // 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);
        }
示例#2
0
 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();
 }
示例#3
0
        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);
        }
示例#4
0
        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();
        }
示例#5
0
 // 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));
 }
示例#7
0
 public void Initialize(IUnityContainer container)
 {
     dependencyInjectionConfiguration = new DependencyInjectionConfiguration(container);
     dependencyInjectionConfiguration.Configure();
 }
示例#8
0
 private void InitializeDependencyInjection()
 {
     dependencyInjectionConfiguration = new DependencyInjectionConfiguration(DependencyInjection.Container);
     dependencyInjectionConfiguration.Configure();
 }
示例#9
0
        // 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));
        }