Ejemplo n.º 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <FormOptions>(x =>
            {
                x.ValueLengthLimit            = int.MaxValue;
                x.MultipartBodyLengthLimit    = int.MaxValue;
                x.MultipartHeadersLengthLimit = int.MaxValue;
            });
            services.AddOptions();
            services.Configure <OctopostSettings>(this.Configuration.GetSection("OctopostSettings"));
            services.AddSingleton <IConfiguration>(this.Configuration);
            services.AddSingleton <OctopostSettings>(x => x.GetService <IOptions <OctopostSettings> >().Value);
            var settings = services.BuildServiceProvider().GetService <OctopostSettings>();

            this.ConfigureAutomapper();
            services.AddCors();
            var mvc = services.AddMvc(config =>
            {
                config.Filters.Add(typeof(ValidateActionFilter));
            });

            mvc.AddFluentValidation(fv =>
            {
                fv.ValidatorFactoryType = typeof(ValidationService);
                foreach (var assembly in AssemblyUtilities.GetOctopostAssemblies())
                {
                    fv.RegisterValidatorsFromAssembly(assembly);
                }
            });
            services.AddTransient <IValidatorFactory, ValidationService>();
            mvc.AddMvcOptions(o => o.Filters.Add(typeof(GlobalExceptionFilter)));
            services.AddSwaggerGen(x => x.OperationFilter <SwaggerFilter>());
            services.AddWebSocketManager();
            var connectionString = this.Configuration.GetConnectionString("DefaultConnection");

            services.AddDbContext <OctopostDbContext>(options =>
            {
                options.UseMySql(connectionString);
            });

            services.AddSingleton <IUnitOfWorkFactory>(x =>
            {
                var businessRuleRegistry = x.GetService <IBusinessRuleRegistry>();
                var result = new UnitOfWorkFactory(connectionString, businessRuleRegistry);
                return(result);
            });
            this.ConfigureBusinessRules(services);
            services.AddScoped <IPostCreationService, PostCreationService>();
            services.AddSingleton <IPostTaggingService, PostTaggingService>();
            services.AddScoped <IPostFilterService, PostFilterService>();
            services.AddScoped <IVoteCountService, VoteCountService>();
            services.AddScoped <IVoteService, VoteService>();
            services.AddScoped <ILocationNameService, LocationNameService>();
            services.AddScoped <ICommentCreationService, CommentCreationService>();
            services.AddScoped <ICommentFilterService, CommentFilterService>();
            services.AddScoped <IFileService, FileService>();
            services.AddScoped <IQueryService, QueryService>();
            services.AddSingleton <IPagingValidator, PagingValidator>();
            services.AddSingleton <IBusinessRuleRegistry, BaseBusinessRuleRegistry>();
            services.AddSingleton <IAssemblyContainer>(x => new AssemblyContainer(this.GetAssemblies()));
            services.AddSingleton <IApiResultService, ApiResultService>();
            ServiceLocator.SetServiceLocator(() => services.BuildServiceProvider());

            var context = services.BuildServiceProvider().GetService <OctopostDbContext>();

            context.Database.EnsureCreated();

            // This instance needs to be created for the compiler to reference the Octopost.Validation assembly
            var instance = new PostDtoValidator();
        }
Ejemplo n.º 2
0
 private IEnumerable <Assembly> GetAssemblies() =>
 AssemblyUtilities.GetOctopostAssemblies();