// private bool isInMemory; /// <summary> /// Initializes a new instance of the <see cref="BaseContext{TContext}" /> class. /// </summary> /// <param name="options">injected sql connection options</param> /// <param name="adapter">injected adapter</param> /// <param name="logger">injected logger</param> protected BaseContext(ISqlConnectionOptions options, IDbContextOptionsAdapter <TContext> adapter, ILogger logger) : base(Arguments.EnsureNotNull(adapter, nameof(adapter)).Convert(options)) { Arguments.NotNull(options, nameof(options)); Arguments.NotNull(logger, nameof(logger)); this.SqlConnectionConfiguration = options; this.Logger = logger; this.CheckSchemaAgainstEntityModels(); // TODO: //// Database.SetInitializer<TContext>(null); // This only works if CodeMigrations are used //// this.Database.CompatibleWithModel(true); //// Database.SetInitializer(new MigrateDatabaseToLatestVersion<TContext, SchemaValidationConfiguration<TContext>>()); // TODO: //// this.Database.CommandTimeout = (int)this.SqlConnectionConfiguration.CommandTimeout.TotalSeconds; }
/// <summary> /// Registers an Abbotware BaseContext /// </summary> /// <typeparam name="TContext">context type</typeparam> /// <param name="container">container</param> /// <param name="connection">connection configuration</param> /// <param name="adapter">options adapter</param> public static void RegisterAbbotwareContext <TContext>(this IWindsorContainer container, ISqlConnectionOptions connection, IDbContextOptionsAdapter <TContext> adapter) where TContext : BaseContext <TContext> { container = Arguments.EnsureNotNull(container, nameof(container)); connection = Arguments.EnsureNotNull(connection, nameof(connection)); container.Register(Component.For <TContext>() .ImplementedBy <TContext>() .LifestyleTransient() .DependsOn(Dependency.OnValue <ISqlConnectionOptions>(connection)) .DependsOn(Dependency.OnValue <IDbContextOptionsAdapter <TContext> >(adapter))); }
/// <inheritdoc/> protected override void OnRegister(ISqlConnectionOptions configuration, IDbContextOptionsAdapter <TContext> adapter) { this.Container.RegisterAbbotwareContext <TContext>(configuration, adapter); }
/// <summary> /// Registers an Abbotware BaseContext /// </summary> /// <typeparam name="TContext">context type</typeparam> /// <param name="container">container</param> /// <param name="options">connection configuration</param> /// <param name="adapter">options adapter</param> public static void RegisterDbContext <TContext>(this IWindsorContainer container, ISqlConnectionOptions options, IDbContextOptionsAdapter <TContext> adapter) where TContext : DbContext { container = Arguments.EnsureNotNull(container, nameof(container)); adapter = Arguments.EnsureNotNull(adapter, nameof(adapter)); Arguments.NotNull(options, nameof(options)); container.Register(Component.For <TContext>() .ImplementedBy <TContext>() .LifestyleTransient() .DependsOn(Dependency.OnValue <DbContextOptions <TContext> >(adapter.Convert(options)))); }