protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); UnitOfWorkConfig.Configure(); }
public static void AddHealthCheck(this IServiceCollection services, IConfiguration configuration) { var uow = new UnitOfWorkConfig(configuration); services.AddHealthChecks() .AddSqlServer(uow.SqlServerConnectionString, tags: new List <string> { "DB" }); }
public virtual IDataContext Register(UnitOfWorkConfig config) { DataSource dataSource; if (!dataSourcesProvider().TryGetValue(config.SourceName, out dataSource)) { if (config.SourceName == string.Empty) throw new Exception("Default data source is not registered."); throw new Exception(string.Format("Data source with name '{0}' is not registered.", config.SourceName)); } config = new UnitOfWorkConfig(config.SourceName, config.IsolationLevel == IsolationLevel.Unspecified ? dataSource.DefaultIsolationLevel : config.IsolationLevel, config.Require); if (config.Require == Require.New) { return new DataContextDecorator( new DataContext(config, new Lazy<IOrmSession>(() => dataSource.BuildSession(config.IsolationLevel), false), terminationPolicy), contexts); } // ReSharper disable ImplicitlyCapturedClosure var context = (from ctx in contexts where ctx.WrappedContext.Configuration.SourceName == config.SourceName select ctx) .LastOrDefault(); // ReSharper restore ImplicitlyCapturedClosure if (context != null) { if (!context.WrappedContext.Configuration.IsolationLevel.IsCompatible(config.IsolationLevel)) { throw new Exception(string.Format("Isolation level '{0}' is not compatible with '{1}'.", context.WrappedContext.Configuration.IsolationLevel, config.IsolationLevel)); } return new DataContext.Subordinate(context.WrappedContext); } if (config.Require == Require.Existing) throw new Exception( "Unit of work requires existing unit of work at the top level, but nothing has been found."); context = new DataContextDecorator( new DataContext(config, new Lazy<IOrmSession>(() => dataSource.BuildSession(config.IsolationLevel), false), terminationPolicy), contexts); return context; }
public DataContext([NotNull] UnitOfWorkConfig configuration, [NotNull] Lazy<IDataSession> session, [NotNull] ITerminationPolicy terminationPolicy) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (session == null) { throw new ArgumentNullException("session"); } if (terminationPolicy == null) { throw new ArgumentNullException("terminationPolicy"); } this.configuration = configuration; this.session = session; this.terminationPolicy = terminationPolicy; extra = new ExpandoObject(); ((dynamic)extra).Extensions = new Dictionary<string, object>(); }