Example #1
0
        private void RegisterDataAccess(ContainerBuilder builder)
        {
            var dbContextBuilder = new DbContextOptionsBuilder <EFContext>();

            dbContextBuilder.UseNpgsql(_connectionString);
            var efContextOptions = new EFContextOptions
            {
                DbContextOptions = dbContextBuilder.Options,
                SystemUserId     = _costAdminUserId
            };

            builder.RegisterInstance(efContextOptions);
            builder.RegisterModule <DataAccessModule>();
        }
Example #2
0
        private void RegisterDataAccess(IConfigurationRoot config, ContainerBuilder builder)
        {
            var dbContextBuilder = new DbContextOptionsBuilder <EFContext>();

            dbContextBuilder.UseNpgsql(config.GetSection("Data:DatabaseConnection:ConnectionString").Value);
            var costAdminId      = Guid.Parse(config.GetSection($"{nameof(AppSettings)}:{nameof(AppSettings.CostsAdminUserId)}").Value);
            var efContextOptions = new EFContextOptions
            {
                DbContextOptions = dbContextBuilder.Options,
                SystemUserId     = costAdminId
            };

            builder.RegisterInstance(efContextOptions);
            builder.RegisterModule <DataJobAccessModule>();
        }
        public static T CreateInMemoryEFContext <T>(Func <EFContextOptions, T> efContectFactory, Guid?systemUserId = null)
            where T : EFContext
        {
            var modelBuilder = new ModelBuilder(new Microsoft.EntityFrameworkCore.Metadata.Conventions.ConventionSet());

            EFContext.FixSnakeCaseNames(modelBuilder);
            EFMappings.DefineMappings(modelBuilder);

            var dbContextOptions = new DbContextOptionsBuilder <T>()
                                   .UseInMemoryDatabase("costs")
                                   .UseModel(modelBuilder.Model)
                                   .ConfigureWarnings(wcb => wcb.Ignore(InMemoryEventId.TransactionIgnoredWarning))
                                   .Options;

            var efContextOptions = new EFContextOptions
            {
                DbContextOptions = dbContextOptions,
                SystemUserId     = systemUserId ?? Guid.Empty
            };

            return(efContectFactory(efContextOptions));
        }
 public EFContextTest(EFContextOptions options, ILoggerFactory loggerFactory) : base(options, loggerFactory)
 {
 }