Blog Layout

Unity BootStrapper utilizing Microsoft's Enterprise Library, Prism, and Nuget

E.DIN Editor • May 20, 2015
// NOTE: Unity BootStrapper utilizing Microsoft's Enterprise Library Exception Handling & Prism via Nuget Libraries
// NOTE: The AuthenticateUser is required during loading, in this case, in order to load primary service interfaces
//NOTE** CallbackLogger is used only for custom error handling during bootstrap loading
();
}

protected override void InitializeShell()
{
Application.Current.MainWindow = (ShellView) Shell;
Application.Current.MainWindow.Show();
}

public void ShowErrorWindow(string errorMsg)
{
Application.Current.MainWindow = new ErrorWindow(errorMsg);
Application.Current.MainWindow.Show();
}

protected override IModuleCatalog CreateModuleCatalog()
{
//NOTE** set the prism catalog directory to the root of the deployed executable
var moduleCatalog = new DirectoryModuleCatalog {ModulePath = @"."};
return moduleCatalog;
}

protected override ILoggerFacade CreateLogger()
{
return new EnterpriseLibraryLoggerAdapter();
}

protected override void ConfigureContainer()
{
//NOTE** Calling this first to log any unhandled errors during Bootstrapper load
Container.RegisterInstance(m_callBackLogger);

//NOTE** singleton objects
Container.RegisterInstance (UserMainObject);

Container.RegisterInstance (DataLookupModelObject);

//NOTE** SINGLETON CHECKING STATEMENT
//bool singleton = ReferenceEquals(Container.Resolve (), Container.Resolve ());

Container.RegisterType ();
Container.RegisterType ();
Container.RegisterType ();
Container.RegisterType ();
Container.RegisterType (new InjectionConstructor());
Container.RegisterType ();
Container.RegisterType ();
Container.RegisterType ();

//NOTE** Call Exception Handling Block after the log is created in the Prism Bootstrapper
BootstrapExceptionHandlingBlock();

//NOTE** Container is required to register variant Prism infrastructure services
base.ConfigureContainer();

//NOTE** TEST CASE FOR UNHANDLED EXCEPTION HERE using the CallbackLogger >>
// throw new Exception("TESTING BOOTSTRAPPER EXCEPTION");
}

protected override Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
{
var factory = base.ConfigureDefaultRegionBehaviors();
return factory;
}


private void BootstrapExceptionHandlingBlock()
{
Container.RegisterType (
new InjectionConstructor(new List
{
new ExceptionPolicyDefinition(ExceptionCategory.DEFAULT, ConfigureDefaultPolicy()),
new ExceptionPolicyDefinition(ExceptionCategory.DATA, ConfigureDataPolicy()),
new ExceptionPolicyDefinition(ExceptionCategory.SERVICE, ConfigureServicePolicy()),
new ExceptionPolicyDefinition(ExceptionCategory.UI, ConfigureUiPolicy())
})
);
}

private static IEnumerable ConfigureUiPolicy()
{
var uiPolicyObject = new List
{
new ExceptionPolicyEntry(
typeof (Exception),
PostHandlingAction.ThrowNewException,
new IExceptionHandler[]
{
new LoggingExceptionHandler(
"Error",
100,
TraceEventType.Error,
"UI Error",
0,
typeof (TextExceptionFormatter),
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Writer)
})
};

return uiPolicyObject;
}

private static IEnumerable ConfigureServicePolicy()
{
var servicePolicyObject = new List
{
new ExceptionPolicyEntry(
typeof (Exception),
PostHandlingAction.ThrowNewException,
new IExceptionHandler[]
{
new LoggingExceptionHandler(
"Error",
100,
TraceEventType.Error,
"Service Error",
0,
typeof (TextExceptionFormatter),
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Writer)
})
};

return servicePolicyObject;
}

private static IEnumerable ConfigureDefaultPolicy()
{
var dataPolicyObject = new List
{
new ExceptionPolicyEntry(
typeof (Exception),
PostHandlingAction.None,
new IExceptionHandler[]
{
new LoggingExceptionHandler(
"Error",
100,
TraceEventType.Error,
"Default Error",
0,
typeof (TextExceptionFormatter),
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Writer)
})
};

return dataPolicyObject;
}

private static IEnumerable ConfigureDataPolicy()
{
var dataPolicyObject = new List
{
new ExceptionPolicyEntry(
typeof (Exception),
PostHandlingAction.ThrowNewException,
new IExceptionHandler[]
{
new LoggingExceptionHandler(
"Critical",
100,
TraceEventType.Critical,
"Data Error",
0,
typeof (TextExceptionFormatter),
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Writer)
})
};

return dataPolicyObject;
}

public void ExitApplication()
{
Application.Current.Shutdown();
}
}
}
By E.DIN Editor 17 Nov, 2021
Title: Base64 Encoding With Simple Salt (and decoding)
By E.DIN Editor 17 Nov, 2021
XPCMD_SHELL Move & Load Data from Directory
By E.DIN Editor 17 Nov, 2021
By E.DIN Editor 17 Nov, 2021
By E.DIN Editor 01 Oct, 2020
 ***** My Valid Data Monitor **** XML OUT *** HTML EMAIL DELIVERY  *****IF OBJECT_ID('tempdb..#tCustomerID') IS NOT NULL DROP TABLE #tCustomerID    select distinct         mm.CustomerID  Into #tCustomerID    from myDatabase..myTable (nolock) mm     left join myDatabase.dbo.myOtherTable (nolock) mo  on mm.refID = mo.id     left join myDatabase.dbo.myOtherTableDetail (nolock) mod  on mo.id = mod.myOtherTableid         and mm.SearchValue = mod.SearchValue     where mm.refID is not null     and mm.quantity is not null      and mod.SearchValue is nullIF Exists (Select 1 From #tCustomerID)BEGIN DECLARE @xml NVARCHAR(MAX)DECLARE @body NVARCHAR(MAX)SET @xml = CAST(( SELECT [CustomerID] AS 'td' FROM #tCustomerID ORDER BY CustomerID FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))SET @body ='

My Valid Data Monitor

'    SET @body = @body + @xml +'
CustomerID
'--SELECT @body  exec msdb.dbo.sp_send_dbmail  @profile_name  = 'dbmailProfile' ,@recipients    = 'usergroup@mydomain.com' ,@subject       = 'My Valid Data Monitor' ,@body          = @body ,@body_format   = 'HTML'END
By websitebuilder 20 Sep, 2020
The new season is a great reason to make and keep resolutions. Whether it’s eating right or cleaning out the garage, here are some tips for making and keeping resolutions.
By websitebuilder 20 Sep, 2020
There are so many good reasons to communicate with site visitors. Tell them about sales and new products or update them with tips and information.
By websitebuilder 20 Sep, 2020
Write about something you know. If you don’t know much about a specific topic that will interest your readers, invite an expert to write about it.
By tekp 15 Jul, 2020
Turn Up! Not every microphone has the same base volume for transmitting your voice through your computer to whoever or whatever is on the other end of the exchange. Some microphones have a higher volume as compared to others, and some microphones have a volume that is so low that the person on the other […] The post How to Turn Up Mic Volume in Windows 10 – Appuals.com appeared first on TekPreacher.
By E.DIN Editor 09 Jun, 2020
'+@UNCPathAndLogTable+'
More Posts
Share by: