Beispiel #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 public MailDemonDatabase() : this(MailDemonDatabaseSetup.ConfigureDB(null))
 {
 }
Beispiel #2
0
 public RazorRenderer(string rootPath)
 {
     this.rootPath = rootPath;
     services      = new ServiceCollection();
     ConfigureDefaultServices(services);
     Microsoft.EntityFrameworkCore.DbContextOptions <MailDemonDatabase> dbOptions = MailDemonDatabaseSetup.ConfigureDB(null);
     services.AddTransient <MailDemonDatabase>((provider) => new MailDemonDatabase(dbOptions));
     serviceProvider = services.BuildServiceProvider();
     viewRenderer    = new ViewRenderService(rootPath, serviceProvider.GetRequiredService <IRazorViewEngine>(), null, null, serviceProvider);
 }
Beispiel #3
0
        IServiceProvider IStartup.ConfigureServices(IServiceCollection services)
        {
            services.AddMemoryCache((o) =>
            {
                o.CompactionPercentage    = 0.9;
                o.ExpirationScanFrequency = TimeSpan.FromMinutes(1.0);
                o.SizeLimit = 1024 * 1024 * 32; // 32 mb
            });
            bool enableWeb = bool.Parse(Configuration.GetSection("mailDemonWeb")["enable"]);

            if (enableWeb)
            {
                services.Configure <CookiePolicyOptions>(options =>
                {
                    options.CheckConsentNeeded    = context => true;
                    options.MinimumSameSitePolicy = SameSiteMode.None;
                });
                services.Configure <CookieTempDataProviderOptions>(options =>
                {
                    options.Cookie.IsEssential = true;
                });
                services.Configure <GzipCompressionProviderOptions>(options => options.Level = System.IO.Compression.CompressionLevel.Optimal);
                services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(o =>
                {
                    o.AccessDeniedPath = "/MailDemonLogin";
                    o.LoginPath        = "/MailDemonLogin";
                    o.LogoutPath       = "/MailDemonLogin";
                    o.Cookie.HttpOnly  = true;
                });
                services.AddResponseCompression(options => { options.EnableForHttps = true; });
                services.AddResponseCaching();
                services.AddHttpContextAccessor();
                services.AddSingleton <IMailSender>((provider) => mailService);
                services.AddSingleton <IBulkMailSender>((provider) => new BulkMailSender(provider));
                services.AddSingleton <IViewRenderService, ViewRenderService>();
                services.AddSingleton <IAuthority>(this);
                services.AddSingleton <IMailDemonDatabaseProvider>(this);
                services.AddTransient <IMailCreator, MailCreator>();
                Microsoft.EntityFrameworkCore.DbContextOptions <MailDemonDatabase> dbOptions = MailDemonDatabaseSetup.ConfigureDB(Configuration);
                services.AddTransient <MailDemonDatabase>((provider) => new MailDemonDatabase(dbOptions));
                services.AddHostedService <SubscriptionCleanup>();
                services.AddDataProtection().SetApplicationName(GetType().Name).PersistKeysToFileSystem(new System.IO.DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory));
                services.AddMvc((options) =>
                {
                }).SetCompatibilityVersion(CompatibilityVersion.Latest).AddJsonOptions(options =>
                {
                    options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
                });
                services.Configure <RazorViewEngineOptions>(opts =>
                {
                    opts.AllowRecompilingViewsOnFileChange = true;
                    opts.FileProviders.Add(new MailDemonDatabaseFileProvider(this, RootDirectory));
                });
                services.AddAntiforgery(options =>
                {
                    options.Cookie.Name   = "ANTI_FORGERY_C";
                    options.FormFieldName = "ANTI_FORGERY_F";
                    options.HeaderName    = "ANTI_FORGERY_H";
                    options.SuppressXFrameOptionsHeader = false;
                });
            }
            return(serviceProvider = services.BuildServiceProvider());
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="config">Configuration</param>
 public MailDemonDatabase(IConfiguration config = null) : this(MailDemonDatabaseSetup.ConfigureDB(config))
 {
 }