Beispiel #1
0
        public SqlServerFactory(IMemoryCache memoryCache, ILoggerFactory loggerFactory,
                                IRepositoryOptions options, ILoggedInUserProvider loggedInUserProvider) : base(memoryCache, loggerFactory, options)
        {
            if (!(options is ISqlServerDatabaseOptions sqlServerOptions))
            {
                throw new Exception("Options should be of type IMongoDatabaseOptions");
            }
            _loggedInUserProvider = loggedInUserProvider;
            _dbContext            = new SqlDatabaseContext();
            _logger = loggerFactory.CreateLogger(GetType());
            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            if (string.IsNullOrWhiteSpace(environment))
            {
                environment = "Development";
            }

            var connection =
                new SqlConnectionStringBuilder(sqlServerOptions.ConnectionString)
            {
                InitialCatalog = $"{sqlServerOptions.DatabaseName}-{environment}"
            };

            ConnectionString = connection.ConnectionString;
            Repositories     = new ConcurrentDictionary <Type, object>();
        }
 public SqlServerRepository(ILoggerFactory loggerFactory, SqlDatabaseContext context)
 {
     _context = context;
     _context.AddType(typeof(T));
     Logger = loggerFactory.CreateLogger(GetType());
 }