コード例 #1
0
        public static IServiceCollection AddInfraDependency(this IServiceCollection services)
        {
            // Adiciona as principais dependencias do Tnf
            services.AddTnfKernel();

            // Adiciona os registros automaticos de injeção de dependencias do Tnf
            // ITransientDependency
            // IScopedDependency
            // ISingletonDependecy
            services.AddTnfDefaultConventionalRegistrations();

            // Configura o uso do EntityFrameworkCore registrando os contextos que serão
            // usados pela aplicação
            services
            .AddTnfEntityFrameworkCore()
            .AddTnfDbContext <CustomerDbContext>(config => DbContextConfigurer.Configure(config))
            .AddTnfDbContext <EmployeeDbContext>(config => DbContextConfigurer.Configure(config));

            // Configura o uso do AutoMappper
            services.AddTnfAutoMapper(config =>
            {
                config.AddProfile <CustomerProfile>();
                config.AddProfile <EmployeeProfile>();
            });

            return(services);
        }
コード例 #2
0
        public AppDbContext CreateDbContext(string[] args)
        {
            var builder          = new DbContextOptionsBuilder <AppDbContext>();
            var connectionString = AppConfigurations.Configuration.GetConnectionString("Default");

            DbContextConfigurer.Configure(builder, connectionString);
            return(new AppDbContext(builder.Options));
        }
コード例 #3
0
        public ProductDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder <ProductDbContext>();

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

            DbContextConfigurer.Configure(builder, connectionString);

            return(new ProductDbContext(builder.Options));
        }
コード例 #4
0
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var configuration = context.Services.GetConfiguration();

            var connectionString = configuration.GetConnectionString("PostgreSQL");

            context.Services.AddAbpDbContext <MyMessengerDbContext>(options =>
            {
                DbContextConfigurer.Configure(options, connectionString);
            });
        }
コード例 #5
0
 public override void PreInitialize()
 {
     if (!SkipDbContextRegistration)
     {
         Configuration.Modules.AbpEfCore().AddDbContext << %= projectName % > DbContext > (options =>
         {
             if (options.ExistingConnection != null)
             {
                 < %= projectName % > DbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
             }
             else
             {
コード例 #6
0
        public static IServiceCollection AddInfraDependency(this IServiceCollection services)
        {
            // Configura o uso do EntityFrameworkCore registrando os contextos que serão
            // usados pela aplicação
            services
            .AddTnfEntityFrameworkCore()
            .AddTnfDbContext <PurchaseOrderContext>(config => DbContextConfigurer.Configure(config));

            services.AddTransient <IPurchaseOrderRepository, PurchaseOrderRepository>();

            return(services);
        }
コード例 #7
0
        public static void AddProductEntityFramework(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddTransient <IUnitOfWork <ProductDbContext>, UnitOfWork <ProductDbContext> >();

            services.AddScoped <IProductRepository, ProductRepository>();
            services.AddScoped <IProductFamilyRepository, ProductFamilyRepository>();
            services.AddScoped <IProductDetailRepository, ProductDetailRepository>();

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

            services.AddDbContext <ProductDbContext>(options =>
                                                     DbContextConfigurer.Configure(options, connectionString));
        }
コード例 #8
0
        public static void AddInfraDependency(this IServiceCollection services)
        {
            // Configura o uso do EntityFrameworkCore registrando os contextos que serão
            // usados pela aplicação
            services
            .AddTnfEntityFrameworkCore()
            .AddTnfDbContext <CustomerDbContext>(config => DbContextConfigurer.Configure(config));

            // Configura o uso do AutoMappper
            services.AddTnfAutoMapper(config =>
            {
                config.AddProfile <CustomerProfile>();
            });
        }
コード例 #9
0
        public LegacyDbContext Create(DbContextFactoryOptions options)
        {
            var builder = new DbContextOptionsBuilder <LegacyDbContext>();

            var assemblyPath = typeof(EntityFrameworkModule).GetAssembly().Location;
            var assemblyName = typeof(EntityFrameworkModule).GetAssembly().GetName().Name;

            var assemblyConfig = assemblyPath.Substring(0, assemblyPath.IndexOf(@"\src\", StringComparison.Ordinal) + 5);

            assemblyConfig = Path.Combine(assemblyConfig, assemblyName);

            var configuration = AppConfigurations.Get(assemblyConfig);

            DbContextConfigurer.Configure(builder, configuration.GetConnectionString(AppConsts.ConnectionStringName));

            return(new LegacyDbContext(builder.Options));
        }
コード例 #10
0
        public static IServiceCollection AddInfraDependency(this IServiceCollection services)
        {
            // Configura o uso do Dapper registrando os contextos que serão
            // usados pela aplicação
            services
            .AddTnfEntityFrameworkCore()
            .AddTnfDbContext <PurchaseOrderContext>(config => DbContextConfigurer.Configure(config))
            .AddTnfDapper(options =>
            {
                options.MapperAssemblies.Add(typeof(CustomerMapper).Assembly);
                options.DbType = DapperDbType.SqlServer;
            });

            services.AddTnfAutoMapper(config =>
            {
                config.AddProfile <PurchaseOrderProfile>();
            });

            services.AddTransient <IPurchaseOrderRepository, PurchaseOrderRepository>();

            return(services);
        }