protected void Application_Start() { AreaRegistration.RegisterAllAreas(); BundleConfig.RegisterBundles(BundleTable.Bundles); RouteConfig.RegisterRoutes(RouteTable.Routes); UserConfiguration.Initialize(); RegisterDependencyResolver(); try { new AutomaticUpdater().Run(); new RepositorySynchronizer().Run(); } catch (Exception ex) { Trace.WriteLine("StartupException " + ex); throw; } }
protected void Application_Start() { ConfigureLogging(); Log.Information("Bonobo starting"); AreaRegistration.RegisterAllAreas(); BundleConfig.RegisterBundles(BundleTable.Bundles); RouteConfig.RegisterRoutes(RouteTable.Routes); UserConfiguration.Initialize(); RegisterDependencyResolver(); GlobalFilters.Filters.Add((AllViewsFilter)DependencyResolver.Current.GetService <AllViewsFilter>()); var connectionstring = WebConfigurationManager.ConnectionStrings["BonoboGitServerContext"]; if (connectionstring.ProviderName.ToLowerInvariant() == "system.data.sqlite") { if (!connectionstring.ConnectionString.ToLowerInvariant().Contains("binaryguid=false")) { Log.Error("Please ensure that the sqlite connection string contains 'BinaryGUID=false;'."); throw new ConfigurationErrorsException("Please ensure that the sqlite connection string contains 'BinaryGUID=false;'."); } } try { AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier; new AutomaticUpdater().Run(); new RepositorySynchronizer().Run(); } catch (Exception ex) { Log.Error(ex, "Startup exception"); throw; } }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { ConfigureLogging(hostingEnvironment); Log.Information("Bonobo starting"); UserConfiguration.Initialize(hostingEnvironment); //GlobalFilters.Filters.Add((AllViewsFilter)DependencyResolver.Current.GetService<AllViewsFilter>()); var connectionstring = ConfigurationManager.ConnectionStrings["BonoboGitServerContext"]; if (connectionstring.ProviderName.ToLowerInvariant() == "system.data.sqlite") { if (!connectionstring.ConnectionString.ToLowerInvariant().Contains("binaryguid=false")) { Log.Error("Please ensure that the sqlite connection string contains 'BinaryGUID=false;'."); throw new ConfigurationErrorsException("Please ensure that the sqlite connection string contains 'BinaryGUID=false;'."); } } services.AddDbContextPool <BonoboGitServerContext>(options => options.UseSqlite(connectionstring.ConnectionString)); services.AddMvc(); services.AddHttpContextAccessor(); services.AddAntiforgery(); services.AddAuthorization(options => { options.AddPolicy("Web", builder => builder.Requirements.Add(new WebRequirement())); options.AddPolicy("WebRepository", builder => builder.Requirements.Add(new WebRequirement())); options.AddPolicy("Git", builder => builder.Requirements.Add(new GitRequirement())); }); services.AddSingleton <IAuthorizationHandler, WebAuthorizationHandler>(); //services.AddSingleton<IAuthorizationHandler, WebRepositoryAuthorizationHandler>(); //services.AddSingleton<IAuthorizationHandler, GitAuthorizationHandler>(); switch (AuthenticationSettings.MembershipService.ToLowerInvariant()) { case "activedirectory": services.AddTransient <IMembershipService, ADMembershipService>(); services.AddTransient <IRoleProvider, ADRoleProvider>(); services.AddTransient <ITeamRepository, ADTeamRepository>(); services.AddTransient <IRepositoryRepository, ADRepositoryRepository>(); services.AddTransient <IRepositoryPermissionService, RepositoryPermissionService>(); break; case "internal": var sp = services.BuildServiceProvider(); services.AddTransient <IMembershipService, EFMembershipService>(x => new EFMembershipService(() => sp.GetService <BonoboGitServerContext>())); services.AddTransient <IRoleProvider, EFRoleProvider>(x => new EFRoleProvider(() => sp.GetService <BonoboGitServerContext>())); services.AddTransient <ITeamRepository, EFTeamRepository>(x => new EFTeamRepository(() => sp.GetService <BonoboGitServerContext>())); services.AddTransient <IRepositoryRepository, EFRepositoryRepository>(x => new EFRepositoryRepository(() => sp.GetService <BonoboGitServerContext>())); services.AddTransient <IRepositoryPermissionService, RepositoryPermissionService>(); break; default: throw new ArgumentException("Missing declaration in web.config", "MembershipService"); } switch (AuthenticationSettings.AuthenticationProvider.ToLowerInvariant()) { case "windows": services.AddTransient <IAuthenticationProvider, WindowsAuthenticationProvider>(); break; case "cookies": services.AddTransient <IAuthenticationProvider, CookieAuthenticationProvider>(); break; case "federation": services.AddTransient <IAuthenticationProvider, FederationAuthenticationProvider>(); break; default: throw new ArgumentException("Missing declaration in web.config", "AuthenticationProvider"); } services.BuildServiceProvider().GetService <IAuthenticationProvider>().Configure(services); services.AddTransient <IGitRepositoryLocator, ConfigurationBasedRepositoryLocator>(serviceProvider => new ConfigurationBasedRepositoryLocator(UserConfiguration.Current.Repositories) ); services.AddSingleton( new GitServiceExecutorParams { GitPath = GetRootPath(hostingEnvironment, ConfigurationManager.AppSettings["GitPath"]), GitHomePath = GetRootPath(hostingEnvironment, ConfigurationManager.AppSettings["GitHomePath"]), RepositoriesDirPath = UserConfiguration.Current.Repositories, }); services.AddTransient <IDatabaseResetManager, DatabaseResetManager>(); if (AppSettings.IsPushAuditEnabled) { EnablePushAuditAnalysis(services); } services.AddTransient <IGitService, GitServiceExecutor>(); }