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

            services.AddLocalization(options => options.ResourcesPath = "GlobalResources");

            ConfigureAuthPolicy(services);


            var mappingProvider = new MappingProvider();

            services.AddSingleton(mappingProvider.CreateMapper());


            services.Configure <cloudscribe.Web.SimpleAuth.Models.SimpleAuthSettings>(Configuration.GetSection("SimpleAuthSettings"));
            services.Configure <MultiTenancyOptions>(Configuration.GetSection("MultiTenancy"));

            services.AddMultitenancy <TenantSettings, CachingSiteResolver>();
            services.AddScoped <cloudscribe.Web.SimpleAuth.Models.IUserLookupProvider, SiteUserLookupProvider>();
            services.AddScoped <cloudscribe.Web.SimpleAuth.Models.IAuthSettingsResolver, SiteAuthSettingsResolver>();
            services.AddCloudscribeSimpleAuth();



            services.AddCloudscribeNavigation(Configuration.GetSection("NavigationOptions"));


            services.AddCloudscribeFileManager(Configuration);


            // Add MVC services to the services container.
            services.Configure <MvcOptions>(options =>
            {
                // options.InputFormatters.Add(new Xm)
                options.CacheProfiles.Add("SiteMapCacheProfile",
                                          new CacheProfile
                {
                    Duration = 30
                });

                options.CacheProfiles.Add("RssCacheProfile",
                                          new CacheProfile
                {
                    Duration = 100
                });
            });

            services.AddRouting(options =>
            {
                options.LowercaseUrls = true;
            });

            services.AddMvc()
            .AddRazorOptions(options =>
            {
                // if you download the cloudscribe.Web.Navigation Views and put them in your views folder
                // then you don't need this line and can customize the views
                options.AddEmbeddedViewsForNavigation();


                options.AddEmbeddedViewsForSimpleAuth();



                options.AddBootstrap3EmbeddedViewsForFileManager();

                options.ViewLocationExpanders.Add(new SiteViewLocationExpander());
            });
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            if (_env.IsProduction())
            {
                // Connect to Redis database.
                try
                {
                    var redisHostName = Environment.GetEnvironmentVariable("REDIS_HOST_NAME");

                    var redisHostPort = Environment.GetEnvironmentVariable("REDIS_HOST_PORT");

                    // Get DNS host information.
                    var hostAdressesTask = Dns.GetHostAddressesAsync(redisHostName);

                    hostAdressesTask.Wait();

                    var redisHost = hostAdressesTask.Result.First();

                    var redis = ConnectionMultiplexer.Connect($"{redisHost.MapToIPv4()}:{redisHostPort}");
                    services.AddDataProtection()
                    .PersistKeysToRedis(redis, "DataProtection-Keys")
                    .SetDefaultKeyLifetime(TimeSpan.FromDays(14));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }

            var mappingProvider = new MappingProvider();

            services.AddSingleton(mappingProvider.CreateMapper());
            services.AddSingleton <IUserIdentityProvider, AspNetUserIdentityProvider>();
            services.AddSingleton <IJsonSerializer, JsonSerializer>();
            //services.AddMultitenancy<TenantSettingsDto, CachingTenantResolver>();

            services.AddSingleton(new AuthMessageSenderOptions
            {
                DefaultSenderEmail = Environment.GetEnvironmentVariable("EMAIL_DEFAULT_SENDER_EMAIL") ?? "*****@*****.**",
                DefaultSenderName  = Environment.GetEnvironmentVariable("EMAIL_DEFAULT_SENDER_NAME") ?? "Lot Of Ideas",
                ElasticEmailApiKey = Environment.GetEnvironmentVariable("EMAIL_ELASTICEMAIL_API_KEY")
            });

            // Add application services.
            services.AddSingleton <IEmailSender, AuthMessageSender>();
            services.AddSingleton <ISmsSender, AuthMessageSender>();

            var dbHost = Environment.GetEnvironmentVariable("DB_HOSTS");

            services.AddSingleton(new ConnectionOptions
            {
                DBName    = Environment.GetEnvironmentVariable("DB_NAME") ?? "ideas",
                HostNames = string.IsNullOrEmpty(dbHost) ? new[] { "localhost" } : Environment.GetEnvironmentVariable("DB_HOSTS").Split(';'),
                Port      = 28015
            });

            services.AddScoped <ITenantLogic, TenantLogic>();
            services.AddScoped <IIdeaLogic, IdeaLogic>();
            services.AddScoped <ITeamLogic, TeamLogic>();
            services.AddScoped <IIdeaCollaborationLogic, IdeaCollaborationLogic>();
            services.AddScoped <IUserProfileLogic, UserProfileLogic>();
            services.AddScoped <IActivityLogic, ActivityLogic>();
            services.AddScoped <ITaskBoardLogic, TaskBoardLogic>();

            services.AddScoped <IEventStore, DefaultEventStore>();

            services.AddScoped <IBus, InMemoryBus>();

            services.AddScoped <ITenantStore, LocalJsonTenantStore>();


            services.AddScoped <ITenantService, TenantService>();
            services.AddScoped <IIdeaService, IdeaService>();
            services.AddScoped <ITeamService, TeamService>();
            services.AddScoped <IIdeaCollaborationService, IdeaCollaborationService>();
            services.AddScoped <IUserProfileService, UserProfileService>();
            services.AddScoped <ITaskBoardService, TaskBoardService>();


            services.AddScoped <IRethinkDbConnectionProvider, DefaultRethinkDbConnectionProvider>();

            services.AddScoped <IRepository, RethinkDbRepository>();
            services.AddScoped <IFileStorage, ReGridStorageProvider>();

            services.AddSingleton <DatabaseConfigurator>();

            // Add framework services.

            services.AddIdentity <ApplicationUser, RepositoryIdentityRole>(options =>
            {
                options.Password.RequireUppercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireDigit           = false;

                options.SignIn.RequireConfirmedEmail = true;
            })
            .AddRoleStore <RepositoryRoleStore <RepositoryIdentityRole> >()
            .AddUserStore <RepositoryUserStore <ApplicationUser> >()
            .AddDefaultTokenProviders();

            services.AddMvc();



            var type1 = typeof(FilterIdeaQueryTemplate);
            var type2 = typeof(LikeIdeaCommand);
            var type3 = typeof(IdeaLikeChangedEvent);

            var allExportedTypes = Assembly.GetEntryAssembly()
                                   .GetReferencedAssemblies()
                                   .Select(i => Assembly.Load(i))
                                   .SelectMany(i => i.GetTypes())
                                   .ToList();

            RegisterAllGenericTypeImplementations(services, allExportedTypes, typeof(Message), typeof(IMessageFilter <>));
            RegisterAllGenericTypeImplementations(services, allExportedTypes, typeof(Command), typeof(IHandler <>));
            RegisterAllGenericTypeImplementations(services, allExportedTypes, typeof(Event), typeof(IHandler <>));


            RegisterQueryTemplates(services, allExportedTypes);



            using (var scope = services.BuildServiceProvider().CreateScope())
            {
                scope.ServiceProvider
                .GetService <DatabaseConfigurator>()
                .EnsureDB()
                .EnsureTables(nameof(ApplicationUser),
                              nameof(Idea),
                              nameof(IdeaComment),
                              nameof(IdeaLike),
                              nameof(Team),
                              nameof(Page),
                              nameof(StoredEvent),
                              nameof(UserProfile),
                              nameof(Activity))
                .EnsureTableIndex(nameof(Idea), nameof(IdeaComment.OwnerId))
                .EnsureTableIndex(nameof(Idea), nameof(Idea.Comments))
                .EnsureTableIndex(nameof(IdeaComment), nameof(IdeaComment.CreatedOn))
                .EnsureTableIndex(nameof(IdeaComment), nameof(IdeaComment.CreatedOn))
                .EnsureTableIndex(nameof(IdeaLike), nameof(IdeaLike.OwnerId))
                .EnsureTableIndex(nameof(UserProfile), nameof(UserProfile.OwnerId))
                .EnsureTableIndex(nameof(Activity), nameof(Activity.OwnerId))
                .EnsureTableIndex(nameof(Activity), nameof(Activity.CreatedAt));
            }
        }