コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void 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.AddIdentityMongoDbProvider <MaddalenaUser>(mongo =>
            {
                mongo.ConnectionString = ConnectionString;
            });

            var store = GetAnalyticStore(ConnectionString);

            services.AddSingleton <IAnalyticStore>(store);

            services.AddTransient <IEmailSender, EmailSender>();

            var gridFs = new GridFileSystem(ConnectionString, "gridFsTable");

            services.AddSingleton <IGridFileSystem>(gridFs);
            services.AddSingleton <IBlogService>(new MongoBlogService(ConnectionString));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: lulzzz/sito
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddIdentityMongoDbProvider <MaddalenaUser, MongoRole>(options =>
            {
                options.Password.RequiredLength         = 6;
                options.Password.RequireLowercase       = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireDigit           = false;
            }, dbOptions =>
            {
                dbOptions.ConnectionString = Configuration.GetConnectionString("DefaultConnection");
                dbOptions.UsersCollection  = "Users"; // this is the default value;
                dbOptions.RolesCollection  = "Roles"; // this is the default value;
            });

            var connectionString = Configuration.GetConnectionString("DefaultConnection");
            var gridFs           = new GridFileSystem(connectionString, "gridFsTable");

            services.AddSingleton <IServiceCollection>(services);
            services.AddAntiforgery();

            services.AddSingleton <INugetHistoryService>(new NugetHistoryService(connectionString));
            services.AddSingleton <IFeedService>(new MongoFeedService(connectionString));
            services.AddSingleton <IYoutubeService>(new YoutubeService(connectionString));
            services.AddSingleton <IGridFileSystem>(gridFs);
            services.AddSingleton <IScriptService>(new MongoScriptService(connectionString, services.BuildServiceProvider()));
            services.AddSingleton <IFeedService>(new MongoFeedService(connectionString));

            var settings = new SettingsService(connectionString);

            services.AddSingleton <ISettingsService>(settings);

            var orleans = new OrleansHost();

            services.AddSingleton <IOrleansHost>(orleans);

            var webSiteSetting = settings.Get <SiteSettings>();

            if (!string.IsNullOrWhiteSpace(webSiteSetting.GoogleClientId) &&
                !string.IsNullOrWhiteSpace(webSiteSetting.GoogleClientSecret))
            {
                services.AddAuthentication().AddGoogle(googleOptions =>
                {
                    googleOptions.ClientId     = webSiteSetting.GoogleClientId;
                    googleOptions.ClientSecret = webSiteSetting.GoogleClientSecret;
                });
            }

            if (!string.IsNullOrWhiteSpace(webSiteSetting.TwitterConsumerKey) &&
                !string.IsNullOrWhiteSpace(webSiteSetting.TwitterConsumerKey))
            {
                services.AddAuthentication().AddTwitter(twitterOptions =>
                {
                    twitterOptions.ConsumerKey    = webSiteSetting.TwitterConsumerKey;
                    twitterOptions.ConsumerSecret = webSiteSetting.TwitterConsumerKey;
                });
            }

            services.AddTransient <IAnalyticStore, MongoAnalyticStore>(provider => GetAnalyticStore());

            services.AddTransient <IBlogService, MongoBlogService>(provider => new MongoBlogService(Configuration.GetConnectionString("DefaultConnection")));
            // Add application services.
            services.AddTransient <IEmailSender, EmailSender>();

            services.AddMvc();
        }