Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var sqlContextConfigurator = new DbContextConfigurator(Configuration);

            services.AddEntityFramework()
            .AddDbContext <AuthDbContext>(sqlContextConfigurator.Configure)
            .AddDbContext <DataDbContext>(sqlContextConfigurator.Configure);

            // Add Identity services to the services container.
            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <AuthDbContext>()
            .AddDefaultTokenProviders();

            services.Configure <IdentityOptions>(
                // Configure login page path
                x => x.Cookies.ApplicationCookie.LoginPath = new PathString("/Private/Account/Login")
                );

            // Add MVC services to the services container.
            services.AddMvc()
            .AddViewLocalization();

            services.AddTransient <IContentRepository, ContentRepository>();
            services.AddTransient <IApplicationUserRepository, ApplicationUserRepository>();
            services.AddTransient <IHumanReadableContentRetrievalService, HumanReadableContentRetrievalService>();
            services.AddTransient <IRequiredDataRepository, RequiredDataRepository>();
            services.AddTransient <IInternalContentRepository, InternalContentRepository>();

            services.AddTransient <IContentEditorRepository, ContentEditorRepository>();

            services.AddSingleton <IRoutesBuilder, RoutesBuilder>();
            services.AddSingleton <ILanguageManipulationService, LanguageManipulationService>();
            services.AddSingleton <IPageConfiguration, PageConfiguration>();
            services.AddSingleton <IConfiguration>(Configuration);
        }
Пример #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            var sqlContextConfigurator = new DbContextConfigurator(Configuration);

            services.AddEntityFrameworkSqlServer()
            .AddDbContextPool <AuthDbContext>(sqlContextConfigurator.Configure)
            .AddDbContextPool <DataDbContext>(sqlContextConfigurator.Configure);
            services.AddTransient <IDatabaseMigrationsRunner, DatabaseMigrationsRunner>();

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <AuthDbContext>()
            .AddDefaultTokenProviders();

            services.ConfigureApplicationCookie(options => options.LoginPath = "/Private/Account/Login");

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            .AddViewLocalization();

            services.AddTransient <IContentViewerRepository, ContentViewerRepository>();
            services.AddTransient <IApplicationUserRepository, ApplicationUserRepository>();
            services.AddTransient <IHumanReadableContentRetrievalService, HumanReadableContentRetrievalService>();
            services.AddTransient <IRequiredDataRepository, RequiredDataRepository>();
            services.AddTransient <IInternalContentRepository, InternalContentRepository>();

            services.AddTransient <IContentEditorRepository, ContentEditorRepository>();

            services.AddSingleton <IEndpointsBuilder, EndpointsBuilder>();
            services.AddSingleton <ILanguageManipulationService, LanguageManipulationService>();
            services.AddSingleton <IPageConfiguration, PageConfiguration>();
            services.AddSingleton <IConfiguration>(Configuration);
        }
Пример #3
0
        public static void InitDbContext(IConfiguration configuration)
        {
            var appConfigurator = new AppConfigurator(configuration);
            var dbConfiguration = appConfigurator.GetDbConfiguration();
            var context         = DbContextConfigurator.CreateDbContext(dbConfiguration, DbConfigurationOptions.Sql);

            DbContextConfigurator.InitDbContext(context);
        }
Пример #4
0
        private static async Task<TrackTvDbContext> CreateContext()
        {
            var configurator = new DbContextConfigurator();

            var context = new TrackTvDbContext(configurator.GetOptions());

            await context.Database.MigrateAsync();

            configurator.AttachLogger<SqlLoggerProvider>(context);

            return context;
        }
Пример #5
0
        private IServiceProvider RegisterDependencies(IServiceCollection services, IDbConfiguration dbConfiguration)
        {
            var containerBuilder = new ContainerBuilder();

            IdentityConfigurator.RegisterDependencies(containerBuilder);

            var repositoryDependenciesModule = DbContextConfigurator.GetDbContextDependencies(dbConfiguration, DbConfigurationOptions.Sql);

            containerBuilder.AddSharedLoginDependecies <ApplicationDbContext, User, Role, string>(
                mapperConfiguration => {
                mapperConfiguration.AddProfile <Mappings.AccountMappingProfile>();
                mapperConfiguration.AddProfile <Mappings.HistoryMappingProfile>();
            },
                repositoryDependenciesModule);

            containerBuilder.Populate(services);
            return(new AutofacServiceProvider(containerBuilder.Build()));
        }
Пример #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var sqlContextConfigurator = new DbContextConfigurator(Configuration);

            services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext <AuthDbContext>(sqlContextConfigurator.Configure)
            .AddDbContext <DataDbContext>(sqlContextConfigurator.Configure);

            // Add Identity services to the services container.
            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <AuthDbContext>()
            .AddDefaultTokenProviders();

            // Add MVC services to the services container.
            services.AddMvc()
            .AddViewLocalization();

            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();

            // Register application services.
            services.AddTransient <IEmailSender, AuthMessageSender>();
            services.AddTransient <ISmsSender, AuthMessageSender>();

            services.AddTransient <IContentRepository, ContentRepository>();
            services.AddTransient <IApplicationUserRepository, ApplicationUserRepository>();
            services.AddTransient <IHumanReadableContentService, HumanReadableContentService>();
            services.AddTransient <IRequiredDataRepository, RequiredDataRepository>();
            services.AddTransient <IInternalContentRepository, InternalContentRepository>();

            services.AddTransient <IContentEditorRepository, ContentEditorRepository>();

            services.AddSingleton <ILanguageManipulationService, LanguageManipulationService>();
            services.AddSingleton <IPageConfiguration, PageConfiguration>();
            services.AddInstance <IConfiguration>(Configuration);
        }