// Adds each found derived EntityDbContext to the service-collection using
        // the determined service type under which it should be registered.
        public override void RegisterServices(IServiceCollection services)
        {
            foreach (EntityDbRegistration registration in _registrations)
            {
                // Register the context's service type and a factory
                // method that will create and configure the context
                // instance when injected into a dependent component.
                services.AddScoped(registration.ServiceType, sp =>
                {
                    var connSettings = sp.GetService <ConnectionSettings>();
                    if (connSettings == null)
                    {
                        throw new ContainerException(
                            "Application settings for: netfusion:entityFramework not found.");
                    }

                    DbContextSettings contextSettings    = GetSettingsForContext(connSettings, registration);
                    IEntityTypeMapping[] contextMappings = _contextMappings[registration.ImplementationType];

                    // Return instance of a configured context:
                    return(registration.ImplementationType.CreateInstance(
                               contextSettings,
                               contextMappings));
                });
            }
        }
        public static void RegisterDataLayer(this IServiceCollection services, DbContextSettings dbSettings)
        {
            services.AddDbContext <CoinDriveContext>(options => options.UseSqlServer(dbSettings.ConnectionString).EnableSensitiveDataLogging());
            services.AddIdentity <AppUser, AppRole>(options =>
            {
                options.Password.RequireDigit           = true;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequiredLength         = 8;
                options.Password.RequireUppercase       = true;
                options.User.RequireUniqueEmail         = true;
                options.SignIn.RequireConfirmedEmail    = true;
            }).AddEntityFrameworkStores <CoinDriveContext>()
            .AddDefaultTokenProviders();

            services.AddAuthentication().AddCookie(options =>
            {
                options.LoginPath  = "/Account/Login";
                options.LogoutPath = "/Account/SignOut";
            });

            services.AddTransient <IUsersRepository, UsersRepository>();
            services.AddTransient <ITransactionsRepository, TransactionsRepository>();
            services.AddTransient <IInnerTransactionsRepository, InnerTransactionsRepository>();
            services.AddTransient <IAffiliatePayoffsRepository, AffiliatePayoffsRepository>();
        }
 public static void RegisterServices(this IServiceCollection services, DbContextSettings dbSettings)
 {
     services.AddTransient <IUsersService, UsersService>();
     services.AddTransient <IEmailService, EmailService>();
     services.AddTransient <IAdapterApiService, AdapterApiService>();
     services.AddTransient <ITransactionWorkerService, TransactionWorkerService>();
     services.AddTransient <ITransactionsService, TransactionsService>();
     services.RegisterDataLayer(dbSettings);
 }
Exemple #4
0
        protected MongoDbContext(DbContextSettings settings)
        {
            var mongoSettings = MongoClientSettings.FromUrl(new MongoUrl(settings.ConnectionString));
            // mongoSettings.ClusterConfigurator =
            //     builder => builder.Subscribe<CommandStartedEvent>(e =>
            //         Console.WriteLine(e.Command.ToJson(new JsonWriterSettings {Indent = true})));

            var client = new MongoClient(mongoSettings);

            Database = client.GetDatabase(settings.Database);
        }
Exemple #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddOptions();
            services.Configure <IcoAdapterSettings>(options =>
                                                    Configuration.GetSection(nameof(IcoAdapterSettings)).Bind(options));
            services.Configure <DbContextSettings>(options =>
                                                   Configuration.GetSection(nameof(DbContextSettings)).Bind(options));
            services.Configure <MainSettings>(options =>
                                              Configuration.GetSection(nameof(MainSettings)).Bind(options));
            var dbSettings = new DbContextSettings();

            Configuration.GetSection(nameof(DbContextSettings)).Bind(dbSettings);
            services.RegisterServices(dbSettings);

            services.AddDataProtection()
            .PersistKeysToFileSystem(new DirectoryInfo("C:\\storage"))
            .SetApplicationName("myApplicationName");
        }
 /// <summary>
 /// Override this method to configure the database (and other options) to be used for this context.
 /// </summary>
 /// <param name="optionsBuilder">The builder used to provide context options.</param>
 /// <param name="contextSettings">The settings associated with the context.</param>
 protected abstract void ConfigureDbContext(DbContextOptionsBuilder optionsBuilder, DbContextSettings contextSettings);
 protected EntityDbContext(DbContextSettings contextSettings, IEntityTypeMapping[] mappings)
 {
     _contextSettings = contextSettings ?? throw new ArgumentNullException(nameof(contextSettings));
     _mappings        = mappings ?? throw new ArgumentNullException(nameof(mappings));
 }
 /// <summary>Initializes a new instance of the <see cref="PerformanceDatabaseContext"/> class.</summary>
 /// <param name="dbContextSettings">The database context settings.</param>
 public PerformanceDatabaseContext(DbContextSettings dbContextSettings) : base(dbContextSettings.ConnectionName)
 {
     Database.SetInitializer <PerformanceDatabaseContext>(null);
     this.Configuration.UseDatabaseNullSemantics = true;
 }
Exemple #9
0
 public DbContextSettingsTest()
 {
     dbContextSettings = new DbContextSettings();
     jsonFileHandler   = new JSonFilesHandler();
 }