Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new DomainProfile());
                mc.AddProfile(new WebApiProfile());
            });

            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            Register <DomainModule>(services, Configuration);
            Register <InfrastructureModule>(services, Configuration);

            RegisterValidators.Register(services, Configuration);

            services
            .AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(cfg =>
            {
                cfg.RequireHttpsMetadata      = false;
                cfg.SaveToken                 = true;
                cfg.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidIssuer      = Configuration["JwtIssuer"],
                    ValidAudience    = Configuration["JwtIssuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtKey"])),
                    ClockSkew        = TimeSpan.Zero // remove delay of token when expire
                };
            });

            services.AddMvc()
            .AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore)
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2).AddFluentValidation();

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

            services.ConfigureSwaggerGen(options =>
            {
                options.DescribeAllEnumsAsStrings();
                options.OperationFilter <FileUploadOperation>(); //Register File Upload Operation Filter
            });
        }
Beispiel #2
0
        public Startup(IWebHostEnvironment env, IConfiguration configuration) : base(env, configuration)
        {
            RegisterValidators.Add(typeof(IValidator));

            BeforeConfigureServices = services =>
            {
                // Setting

                SystemSetting.Current = Configuration.GetSection <SystemSetting>("Setting");

                // Database

                services.AddGoblinDbContext();

                // Directory Browser

                if (SystemSetting.Current.IsEnableDictionaryBrowser)
                {
                    services.AddDirectoryBrowser();
                }
            };

            BeforeConfigureApp = (app, environment, lifetime) =>
            {
                var resourceFolderPathAbsolute = PathHelper.GetFullPath(SystemSetting.Current.ResourceFolderPath);

                DirectoryHelper.CreateIfNotExist(resourceFolderPathAbsolute);

                // Static Files

                app.UseStaticFiles(new StaticFileOptions
                {
                    FileProvider = new PhysicalFileProvider(resourceFolderPathAbsolute),

                    RequestPath = new PathString(SystemSetting.Current.ResourceFolderEndpoint)
                });

                // Directory Browser

                if (SystemSetting.Current.IsEnableDictionaryBrowser)
                {
                    app.UseDirectoryBrowser(new DirectoryBrowserOptions
                    {
                        FileProvider = new PhysicalFileProvider(resourceFolderPathAbsolute),
                        RequestPath  = new PathString(SystemSetting.Current.ResourceFolderEndpoint)
                    });
                }
            };
        }
Beispiel #3
0
        public Startup(IWebHostEnvironment env, IConfiguration configuration) : base(env, configuration)
        {
            RegisterValidators.Add(typeof(IValidator));

            BeforeConfigureServices = services =>
            {
                // Setting

                SystemSetting.Current = Configuration.GetSection <SystemSetting>("Setting");

                // Database

                services.AddGoblinDbContext();
            };
        }
Beispiel #4
0
        public Startup(IWebHostEnvironment env, IConfiguration configuration) : base(env, configuration)
        {
            RegisterValidators.Add(typeof(IValidator));
            RegisterValidators.Add(typeof(BlogCrawler.Share.Validators.IValidator));
            RegisterValidators.Add(typeof(Identity.Share.Validators.IValidator));
            RegisterValidators.Add(typeof(Notification.Share.Validators.IValidator));

            BeforeConfigureServices = services =>
            {
                // Setting

                SystemSetting.Current = Configuration.GetSection <SystemSetting>("Setting");

                // Blog Crawler Service

                GoblinBlogCrawlerHelper.Domain = SystemSetting.Current.BlogCrawlerServiceDomain;

                GoblinBlogCrawlerHelper.AuthorizationKey = SystemSetting.Current.BlogCrawlerServiceAuthorizationKey;

                // Identity Service

                GoblinIdentityHelper.Domain = SystemSetting.Current.IdentityServiceDomain;

                GoblinIdentityHelper.AuthorizationKey = SystemSetting.Current.IdentityServiceAuthorizationKey;

                // Notification Service

                GoblinNotificationHelper.Domain = SystemSetting.Current.NotificationServiceDomain;

                GoblinNotificationHelper.AuthorizationKey = SystemSetting.Current.NotificationServiceAuthorizationKey;

                // Resource Service

                GoblinResourceHelper.Domain = SystemSetting.Current.ResourceServiceDomain;

                GoblinResourceHelper.AuthorizationKey = SystemSetting.Current.ResourceServiceAuthorizationKey;
            };

            BeforeUseMvc = (app, env, lifetime) =>
            {
                app.UseStatusCodePagesWithReExecute("/error/{0}");
            };
        }
        public async Task <RegisterUserCommandResult> Execute(RegisterUserCommand command)
        {
            if (!RegisterValidators.IsValidRegisterUser(command))
            {
                throw new InvalidOperationException();
            }

            var user = new SimpleUser
            {
                Email    = command.Email,
                UserName = command.Email
            };

            user.PasswordHash = _userManager.PasswordHasher.HashPassword(user, command.Password);
            var result = await _userManager.CreateAsync(user);

            return(new RegisterUserCommandResult {
                Result = result.Succeeded
            });
        }