Exemplo n.º 1
0
        public UnitOfWork(string connection, IContextService env)
        {
            switch (env.InstanceType)
            {
            case InstanceContext.DeployedOrLocal:
            case InstanceContext.End2EndTest:
            {
                _context = new IdentityEntitiesFactory(connection).Create();
#if !RELEASE
                _context.Database.Log = x => Debug.WriteLine(x);
#endif
            }
            break;

            case InstanceContext.SystemTest:
            case InstanceContext.IntegrationTest:
            {
                var memory = Effort.EntityConnectionFactory.CreateTransient(connection);

                _context = new IdentityEntitiesFactory(memory).Create();
#if !RELEASE
                _context.Database.Log = x => Debug.WriteLine(x);
#endif
            }
            break;

            case InstanceContext.UnitTest:
            {
                throw new NotImplementedException();
            }
            break;

            default:
                throw new NotImplementedException();
            }

            _context.Configuration.LazyLoadingEnabled   = false;
            _context.Configuration.ProxyCreationEnabled = true;

            InstanceType = env.InstanceType;

            Audiences    = new AudienceRepository(_context, env);
            AuthActivity = new AuthActivityRepository(_context);
            Claims       = new GenericRepository <tbl_Claim>(_context);
            EmailQueue   = new GenericRepository <tbl_EmailQueue>(_context);
            Issuers      = new GenericRepository <tbl_Issuer>(_context);
            Logins       = new GenericRepository <tbl_Login>(_context);
            MOTDs        = new GenericRepository <tbl_MOTD>(_context);
            Refreshes    = new RefreshRepository(_context);
            Roles        = new GenericRepository <tbl_Role>(_context);
            Settings     = new GenericRepository <tbl_Setting>(_context);
            States       = new GenericRepository <tbl_State>(_context);
            TextQueue    = new GenericRepository <tbl_TextQueue>(_context);
            Urls         = new GenericRepository <tbl_Url>(_context);
            Users        = new UserRepository(_context, env);
        }
Exemplo n.º 2
0
        public UnitOfWork(string connection, IContextService env)
        {
            _logger = LoggerFactory.Create(opt =>
            {
                opt.AddFilter("Microsoft", LogLevel.Warning)
                .AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Warning)
                .AddFilter("System", LogLevel.Warning)
                .AddConsole();
            });

            switch (env.InstanceType)
            {
            case InstanceContext.DeployedOrLocal:
            case InstanceContext.End2EndTest:
            case InstanceContext.SystemTest:
            case InstanceContext.IntegrationTest:
            {
#if !RELEASE
                var builder = new DbContextOptionsBuilder <IdentityEntities>()
                              .UseSqlServer(connection)
                              .UseLoggerFactory(_logger)
                              .EnableSensitiveDataLogging();
#else
                var builder = new DbContextOptionsBuilder <IdentityEntities>()
                              .UseSqlServer(connection);
#endif
                _context = new IdentityEntities(builder.Options);
            }
            break;

            case InstanceContext.UnitTest:
            {
                //_context = Create.MockedDbContextFor<IdentityEntities>();
            }
            break;

            default:
                throw new NotImplementedException();
            }

            _context.ChangeTracker.LazyLoadingEnabled  = false;
            _context.ChangeTracker.CascadeDeleteTiming = CascadeTiming.Immediate;

            InstanceType = env.InstanceType;

            Audiences     = new AudienceRepository(_context, env);
            AuthActivity  = new AuthActivityRepository(_context);
            Claims        = new ClaimRepository(_context);
            EmailActivity = new EmailActivityRepository(_context);
            EmailQueue    = new EmailQueueRepository(_context);
            Issuers       = new IssuerRepository(_context);
            Logins        = new LoginRepository(_context);
            MOTDs         = new MOTDRepository(_context);
            Refreshes     = new RefreshRepository(_context);
            Roles         = new RoleRepository(_context);
            Settings      = new SettingRepository(_context);
            States        = new StateRepository(_context);
            TextActivity  = new TextActivityRepository(_context);
            TextQueue     = new TextQueueRepository(_context);
            Urls          = new UrlRepository(_context);
            Users         = new UserRepository(_context, env);
        }