Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            Compositor compositor = new Compositor();

            compositor.Compose(services);
            ConfigureOptions(services);

            services.AddDbContext <ReviewerDbContext>(o =>
            {
                string connStr = Configuration.GetConnectionString("Dev");
                if (String.IsNullOrWhiteSpace(connStr))
                {
                    throw new Exception($"No connection string defined for {_hostingEnvironment.EnvironmentName}");
                }
                o.UseSqlServer(connStr);
            }, ServiceLifetime.Scoped);

            services.AddMvc();
        }
Пример #2
0
        public void Draw(Graphics graphics)
        {
            _compositor.Compose(_compositeRoot);

            _compositeRoot.Draw(graphics);
        }
Пример #3
0
        // 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 https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            Compositor.Compose(services);

            services.ConfigureFromSection <CryptoOptions>(Configuration);
            services.ConfigureFromSection <JwtOptions>(Configuration);
            services.ConfigureFromSection <EmailOptions>(Configuration);
            services.ConfigureFromSection <ResetPasswordOptions>(Configuration);
            services.ConfigureFromSection <AllowedExtensionsOptions>(Configuration);

            services.AddSingleton <ICryptoContext, AspNetCryptoContext>();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped <IAuthenticatedUser, AuthenticatedUserProvider>();
            services.AddScoped <IRazorViewRenderer, RazorViewRenderer>();
            services.AddScoped <IAuthTokenProvider, AuthTokenProvider>();

            services.AddScoped(typeof(DomainTaskStatus));

            services.AddAuthorization(options => options.AddPolicy(AuthPolicies.AuthenticatedUser, AuthenticatedUserPolicy.Policy));

            services.AddDbContext <HeznekDbContext>(o =>
            {
                string connStr = Configuration.GetConnectionString("Development");
                if (String.IsNullOrWhiteSpace(connStr))
                {
                    throw new Exception($"No connection string defined for {_hostingEnvironment.EnvironmentName}");
                }
                o.UseSqlServer(connStr);
            }, ServiceLifetime.Scoped);

            services.AddCors(o => o.AddPolicy("CORS", builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));

            services.AddMvc().AddJsonOptions(options =>
            {
                //options.SerializerSettings.Converters.Add(new StringEnumConverter
                //{
                //    AllowIntegerValues = true,
                //    CamelCaseText = false
                //});
                options.SerializerSettings.DateParseHandling    = Newtonsoft.Json.DateParseHandling.DateTimeOffset;
                options.SerializerSettings.DateFormatHandling   = Newtonsoft.Json.DateFormatHandling.IsoDateFormat;
                options.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
            })
            .AddFluentValidation(o =>
            {
                o.RegisterValidatorsFromAssemblyContaining <Startup>();
            });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ClockSkew                = TimeSpan.Zero,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer              = Configuration.GetSection("Jwt")["ValidIssuer"],
                    ValidAudience            = Configuration.GetSection("Jwt")["ValidAudience"],
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration.GetSection("Jwt")["Key"]))
                };
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Heznek", Version = "v1"
                });

                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);

                //c.IncludeXmlComments(xmlPath);
            });
        }