コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            #region Mongo

            services.Configure <Models.Mongo.BookstoreDatabaseSettings>(Configuration.GetSection(nameof(Models.Mongo.BookstoreDatabaseSettings)));
            services.AddSingleton <Models.Mongo.IBookstoreDatabaseSettings>(sp => sp.GetRequiredService <IOptions <Models.Mongo.BookstoreDatabaseSettings> >().Value);
            services.AddScoped <Services.Mongo.IBookService, Services.Mongo.BookService>();

            #endregion Mongo

            #region Postgres

            var postgresConnectionString = Configuration.GetConnectionString("PostgreSQLEFCoreDataAccess");

            services.AddDbContext <Models.Postgres.Context>(options =>
            {
                options.UseNpgsql(postgresConnectionString, NpgsqlOptions =>
                {
                    var assembly     = typeof(Models.Postgres.Context).Assembly;
                    var assemblyName = assembly.GetName();

                    NpgsqlOptions.MigrationsAssembly(assemblyName.Name);
                });

                options.ConfigureWarnings(x => x.Ignore(RelationalEventId.AmbientTransactionWarning));
            });

            NpgsqlConnection.GlobalTypeMapper.UseJsonNet();

            services.AddScoped <DbContext, Models.Postgres.Context>();
            services.AddUnitOfWork <Models.Postgres.Context>();
            services.AddScoped <Services.Postgres.IBookService, Services.Postgres.BookService>();

            #endregion Postgres

            // #region MySQL

            // var mySqlConnectionString = Configuration.GetConnectionString("MySQLEFCoreDataAccess");

            // services.AddDbContext<Models.MySQL.Context>(options =>
            // {
            //     options.UseMySql(mySqlConnectionString, mySqlOptions =>
            //     {
            //         var assembly = typeof(Models.MySQL.Context).Assembly;
            //         var assemblyName = assembly.GetName();

            //         mySqlOptions.MigrationsAssembly(assemblyName.Name);
            //     });

            //     options.ConfigureWarnings(x => x.Ignore(RelationalEventId.AmbientTransactionWarning));
            // });

            // services.AddScoped<DbContext, Models.MySQL.Context>();
            // services.AddUnitOfWork<Models.MySQL.Context>();
            // services.AddScoped<Services.MySQL.IBookService, Services.MySQL.BookService>();

            // #endregion MySQL

            services.AddControllers().AddNewtonsoftJson(options => options.UseMemberCasing());
        }
コード例 #2
0
 public void ConfigureDesignTimeServices(IServiceCollection services)
 {
     new EntityFrameworkRelationalServicesBuilder(services).TryAddProviderSpecificServices(x =>
     {
         x.TryAddSingleton <INpgsqlOptions, NpgsqlOptions>(p =>
         {
             var dbOption = new DbContextOptionsBuilder()
                            .UseNpgsql("connection string",
                                       ob => ob.UseNodaTime().UseNetTopologySuite()).Options;
             var npgOptions = new NpgsqlOptions();
             npgOptions.Initialize(dbOption);
             return(npgOptions);
         });
     });
 }
コード例 #3
0
        static NpgsqlNodaTimeTypeMappingTest()
        {
            var optionsBuilder = new DbContextOptionsBuilder();
            var npgsqlBuilder  = new NpgsqlDbContextOptionsBuilder(optionsBuilder).UseNodaTime();
            var options        = new NpgsqlOptions();

            options.Initialize(optionsBuilder.Options);

            Mapper = new NpgsqlTypeMappingSource(
                new TypeMappingSourceDependencies(
                    new ValueConverterSelector(new ValueConverterSelectorDependencies())
                    ),
                new RelationalTypeMappingSourceDependencies(),
                options
                );
        }
        public NpgsqlTypeMappingSourceTest()
        {
            var builder = new DbContextOptionsBuilder();

            new NpgsqlDbContextOptionsBuilder(builder).MapRange <float>("floatrange");
            new NpgsqlDbContextOptionsBuilder(builder).MapRange <DummyType>("dummyrange", subtypeName: "dummy");
            var options = new NpgsqlOptions();

            options.Initialize(builder.Options);

            Source = new NpgsqlTypeMappingSource(
                new TypeMappingSourceDependencies(
                    new ValueConverterSelector(new ValueConverterSelectorDependencies()),
                    Array.Empty <ITypeMappingSourcePlugin>()),
                new RelationalTypeMappingSourceDependencies(
                    new[] { new DummyTypeMappingSourcePlugin() }),
                new NpgsqlSqlGenerationHelper(new RelationalSqlGenerationHelperDependencies()),
                options);
        }