public static IServiceCollection AddDbContextServices(
            this IServiceCollection services,
            IDbContextSettings contextSettings,
            IDbConnectionStrings connectionStrings,
            IWebHostEnvironment hostingEnvironment)
        {
            void CreateOptionsAction(DbContextOptionsBuilder builder)
            {
                builder.EnableDetailedErrors(!hostingEnvironment.IsProduction());
                builder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
                builder.UseSqlServer
                (
                    connectionStrings.SqlConnectionStrings.AtidsXe,
                    _ =>
                {
                    _.EnableRetryOnFailure(contextSettings.MaxRetryCount, contextSettings.MaxRetryDelayTimeSpan, null);
                    _.CommandTimeout(contextSettings.CommandTimeout);
                });
            }

            if (contextSettings.EnablePooling)
            {
                services.AddDbContextPool <ATIDSXEContext>(CreateOptionsAction, contextSettings.PoolSize);
            }
            else
            {
                services.AddDbContext <ATIDSXEContext>(CreateOptionsAction, ServiceLifetime.Transient, ServiceLifetime.Transient);
            }

            return(services);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Construtor padrão
 /// </summary>
 /// <param name="database">Configurações de banco de dados</param>
 /// <param name="logger">Logger</param>
 public PrincipalContext(
     IDbContextSettings database,
     ILogger <PrincipalContext> logger)
 {
     _database = database;
     _logger   = logger;
     ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
     ChangeTracker.LazyLoadingEnabled    = false;
 }
Exemplo n.º 3
0
        public DbContext(IDbContextSettings settings)
        {
            var client   = new MongoClient(settings.ConnectionString);
            var database = client.GetDatabase(settings.DatabaseName);

            DropAllCollections(settings, database);
            GetCollections(settings, database);
            Task.Run(() => Seed()).Wait();
        }
Exemplo n.º 4
0
        public void DropAllCollections(IDbContextSettings settings, IMongoDatabase database)
        {
            try
            {
                database.DropCollection(settings.WeatherCollectionName);
                database.DropCollection(settings.LocationCollectionName);
                database.DropCollection(settings.AccountCollectionName);
            }

            catch (Exception ex) { Console.WriteLine($"Exception DropAllCollections: {ex}"); }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Construtor para migrations
 /// </summary>
 public PrincipalContext()
 {
     _database = new DbContextSettingsLocal();
     _logger   = new LoggerLocal();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="dbContextSettings"></param>
 public ExtendedRoleDbContextFactory(IDbContextSettings dbContextSettings) => _dbContextSettings = dbContextSettings;
Exemplo n.º 7
0
 public void GetCollections(IDbContextSettings settings, IMongoDatabase database)
 {
     _Weather  = database.GetCollection <Weather>(settings.WeatherCollectionName);   //"Weather"
     _Location = database.GetCollection <Location>(settings.LocationCollectionName); //"Location"
     _Account  = database.GetCollection <Account>(settings.AccountCollectionName);   //"Account"
 }
 /// <summary>
 /// Constructor to use
 /// </summary>
 /// <param name="options"></param>
 public ExtendedRoleDbContext(IDbContextSettings options) : base(options.ContextOptions)
 {
 }
Exemplo n.º 9
0
 public DbContext(IDbContextSettings settings) => Database = new MongoClient(settings.ConnectionString).GetDatabase(settings.DatabaseName);