/// <summary> /// Inititializes a new instance of the AppContext class. /// </summary> public AppContextBase(ErrorLoggerBase errorLogger, AuditLoggerBase auditLogger, Action <Action> backgroundAction, AppOptions options) { _errorLogger = errorLogger ?? new TraceErrorLogger(); _auditLogger = auditLogger ?? new TraceAuditLogger(); _backgroundAction = backgroundAction != null ? backgroundAction : (Action action) => ThreadPool.QueueUserWorkItem(a => action()); _options = options ?? new AppOptions(); }
/// <summary> /// Initializes a new instance of the AppContextFactory class. /// </summary> /// <param name="appServices">Injected AppServiceBase types.</param> /// <param name="errorLogger">The default stateless error logger that can be used by app services and the parent application to log errors. If null, the default error logger will output to the console or trace listeners.</param> /// <param name="auditLogger">The default stateless audit logger that can be used by app services and the parent application to log an audit trail. If null, the default audit logger will output to the console or trace listeners.</param> /// <param name="backgroundAction">If null, the default mechanism, ThreadPool.QueueUserWorkItem, is used. NOTE: ASP.NET applications should use (Action action) => HostingEnvironment.QueueBackgroundWorkItem(a => action()). Otherwise, background threads spawned using AppContext.QueueBackgroundAction are subject to AppPool teardowns and may never complete.</param> /// <param name="factoryBackgroundAction">If null, the default mechanism, ThreadPool.QueueUserWorkItem, is used. NOTE: ASP.NET applications should use (Action action) => HostingEnvironment.QueueBackgroundWorkItem(a => action()). Otherwise, background threads spawned using AppContext.QueueBackgroundAction are subject to AppPool teardowns and may never complete.</param> /// <param name="options">A collection of custom options that can be used by AppService UoW classes for application specific purposes.</param> public AppContextFactory(IEnumerable <KeyValuePair <Type, Type> > appServices, ErrorLoggerBase errorLogger, AuditLoggerBase auditLogger, Action <Action> backgroundAction, Action <Action <TAppContext> > factoryBackgroundAction, AppOptions options) { _appServices = appServices != null?appServices.ToList() : new List <KeyValuePair <Type, Type> >(); _errorLogger = errorLogger ?? new TraceErrorLogger(); _auditLogger = auditLogger ?? new TraceAuditLogger(); _backgroundAction = backgroundAction != null ? backgroundAction : (Action action) => ThreadPool.QueueUserWorkItem(a => action()); _factoryBackgroundAction = factoryBackgroundAction != null ? factoryBackgroundAction : (Action <TAppContext> action) => ThreadPool.QueueUserWorkItem(a => { using (var appContext = this.NewAppContext()) { action(appContext); } }); _options = options ?? new AppOptions(); }