public static void Init() { try { BuildConfig(); _connectionString = _config.GetConnectionString("ConnectDataBase"); Console.WriteLine("Recreating database..."); RunRecreateScript(); var configuration = SessionFactory.BuildConfiguration(_connectionString); var sessionFactory = configuration.BuildSessionFactory(); using var session = sessionFactory.OpenSession(); Console.WriteLine("Creating test data..."); CreateTestData(session); } catch (Exception ex) { Console.WriteLine("Error:"); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex); Console.ReadKey(); } }
public static void CreateSessionFactory(this IServiceCollection services, IConfiguration configuration) { var connectionString = configuration.GetConnectionString("b2b"); var cfg = SessionFactory.BuildConfiguration(connectionString); var sessionFactory = cfg.BuildSessionFactory(); services.AddSingleton(sessionFactory); }
private static int Create() { var configuration = SessionFactory.BuildConfiguration(_connectionString); Console.WriteLine("Creating database..."); CreateDatabase(_connectionString, _config); var sessionFactory = configuration.BuildSessionFactory(); using var session = sessionFactory.OpenSession(); Console.WriteLine("Creating test data..."); var testData = new TestData(); testData.CreateAllTestData(); Console.WriteLine("Saving data..."); CreateTestData(session, testData); return(0); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddSingleton(SessionFactory.BuildConfiguration(Configuration.GetConnectionString("proj")) .BuildSessionFactory()); services.AddScoped(x => x.GetServices <ISessionFactory>().First().OpenSession()); services.Configure <IdentityOptions>(opt => { opt.Password.RequiredLength = 6; opt.Password.RequireNonAlphanumeric = false; opt.Password.RequireLowercase = false; opt.Password.RequireUppercase = false; }); services.AddIdentityCore <AppIdentityUser>() .AddDefaultTokenProviders() .AddUserStore <AppIdentityStore>() .AddUserManager <IdentityUserManager>() .AddSignInManager <SignInManager>() .AddErrorDescriber <AppIdentityErrorDescriber>(); services.AddAuthentication(opt => { opt.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme; opt.DefaultChallengeScheme = IdentityConstants.ApplicationScheme; opt.DefaultSignInScheme = IdentityConstants.ApplicationScheme; }).AddIdentityCookies(); services.ConfigureApplicationCookie(opt => { opt.Cookie.HttpOnly = true; opt.ExpireTimeSpan = TimeSpan.FromDays(365); opt.LoginPath = "/Identity/Account/Login"; opt.LogoutPath = "/User/Logout"; opt.AccessDeniedPath = "/Identity/Account/AccessDenied"; }); services.AddDistributedMemoryCache(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <IAppContext, Infrastructure.AppContext>(); services.AddScoped <AppIdentityStore>(); services.AddScoped <AppIdentityErrorDescriber>(); // Lazy services services.AddScoped(provider => new Lazy <IdentityUserManager>(() => provider.GetService <IdentityUserManager>())); services.AddScoped(provider => new Lazy <ProjectRepository>(() => provider.GetService <ProjectRepository>())); services.AddScoped(provider => new Lazy <UserRepository>(() => provider.GetService <UserRepository>())); services.AddScoped(provider => new Lazy <TeamRepository>(() => provider.GetService <TeamRepository>())); services.AddScoped(provider => new Lazy <TaskRepository>(() => provider.GetService <TaskRepository>())); // Repositories services.AddScoped <UserRepository>(); services.AddScoped <UserClaimRepository>(); services.AddScoped <ProjectRepository>(); services.AddScoped <TaskGroupRepository>(); services.AddScoped <TaskRepository>(); services.AddScoped <ChecklistRepository>(); services.AddScoped <ChecklistTaskRepository>(); services.AddScoped <CommentRepository>(); services.AddScoped <TeamRepository>(); // UnitOfWork services.AddScoped <IUnitOfWork, UnitOfWork>(); // Managers services.AddScoped <IUserManager, UserManager>(); services.AddScoped <IUserClaimManager, UserClaimManager>(); services.AddScoped <IProjectManager, ProjectManager>(); services.AddScoped <ITaskGroupManager, TaskGroupManager>(); services.AddScoped <ITaskManager, TaskManager>(); services.AddScoped <IChecklistManager, ChecklistManager>(); services.AddScoped <IChecklistTaskManager, ChecklistTaskManager>(); services.AddScoped <ICommentManager, CommentManager>(); services.AddScoped <ITeamManager, TeamManager>(); }
private static void SetupSingletons(IServiceCollection services, IConfiguration configuration) { services.AddSingleton(SessionFactory.BuildConfiguration(configuration.GetConnectionString("ConnectDataBase")) .BuildSessionFactory()); services.AddSingleton <LocalizationService>(); }