public BlogEntityDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder <BlogEntityDbContext>();

            DbContextOptionsHelper.ConfigureOptionsBuilder(builder, DesignTimeConnectionString);
            return(new BlogEntityDbContext(builder.Options));
        }
        public BlogEntityDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder <BlogEntityDbContext>();

            var connectionString = GetConfiguration().GetConnectionString("DefaultConnection");

            DbContextOptionsHelper.ConfigureOptionsBuilder(builder, connectionString);

            return(new BlogEntityDbContext(builder.Options));
        }
        public BlogSettingsConfigurationProviderTests() : base()
        {
            var connectionStringName = Configuration.GetSection(nameof(PineBlogOptions)).GetValue <string>(nameof(PineBlogOptions.ConnectionStringName));
            var connectionString     = Configuration.GetConnectionString(connectionStringName);

            var optionsAction = DbContextOptionsHelper.Configure(connectionString);

            _provider = new BlogSettingsConfigurationProvider(new BlogSettingsConfigurationSource {
                OptionsAction = optionsAction
            });
        }
示例#4
0
        /// <summary>
        /// Adds PineBlog Entity Framework Core application configuration.
        /// </summary>
        /// <param name="builder">The configuration builder.</param>
        /// <param name="reloadOnChange">Determines whether the source will be loaded if the underlying entity changes.</param>
        /// <returns>The original configuration object.</returns>
        public static IConfigurationBuilder AddPineBlogConfiguration(this IConfigurationBuilder builder, bool reloadOnChange = false)
        {
            var configuration        = builder.Build();
            var connectionStringName = configuration.GetSection(nameof(PineBlogOptions)).GetValue <string>(nameof(PineBlogOptions.ConnectionStringName));
            var connectionString     = configuration.GetConnectionString(connectionStringName);

            var optionsAction = DbContextOptionsHelper.Configure(connectionString);

            return(builder.Add(new BlogSettingsConfigurationSource {
                OptionsAction = optionsAction,
                ReloadOnChange = reloadOnChange
            }));
        }
        /// <summary>
        /// Adds PineBlog Entity Framework Core services to the specified services collection.
        /// </summary>
        /// <param name="services">The services available in the application.</param>
        /// <param name="configuration">The application configuration properties.</param>
        /// <returns>The original services object.</returns>
        public static IServiceCollection AddPineBlogEntityFrameworkCore(this IServiceCollection services, IConfiguration configuration)
        {
            if (((IConfigurationRoot)configuration).Providers.SingleOrDefault(p => p.GetType() == typeof(BlogSettingsConfigurationProvider)) == null)
            {
                throw new ConfigurationException("The PineBlog IConfigurationProvider(s) are not configured, please add \"AddPineBlogConfiguration\" to the \"ConfigureAppConfiguration\" on the \"IWebHostBuilder\".")
                      {
                          HelpLink = "https://github.com/ofpinewood/pineblog/blob/master/docs/getting-started.md#blog-settings-configurationprovider"
                      };
            }

            services.AddDbContextPool <IBlogEntityDbContext, BlogEntityDbContext>((provider, options) =>
            {
                var blogOptions      = provider.GetRequiredService <IOptions <PineBlogOptions> >();
                var connectionString = configuration.GetConnectionString(blogOptions.Value.ConnectionStringName);
                DbContextOptionsHelper.ConfigureOptionsBuilder(options, connectionString);
            });

            return(services);
        }