Although they are different technologies, they share the same basic features. In particular, they all use form objects to implement user interfaces and allow you to specify the code that runs when the application starts. By default, the startup Code only loads and displays the main form, but you can modify it to create a unified container, assemble it with the Enterprise Library Information, and process the objects used in the application. For example, to reduce the startup time and memory usage, you may not want to create all forms at startup. You can store a container object to process the form and other required objects.
WindowsForm application
The following shows howWindowsCreate and assemble the Enterprise Library container in the form
Static void main () <br/>{< br/> var Container = new unitycontainer () <br/>. addnewextension <enterpriselibrarycoreextension> (); <br/> application. run (container. resolve <form1> (); <br/>}< br/>
WPFApplications
WPFThe application uses the startup code to load and display the main form.
When creating a WPF project, Visual Studio creates an application definition file. If C # is used, it is named app. XAML and has an associated code file app. XAML. CS.
XML file content
<Application X: class = "window1" <br/> xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" <br/> xmlns: X = "http://schemas.microsoft.com/winfx/2006/xaml" <br/> startup = "createcontainer"> <br/> <application. resources> </P> <p> </application. resources> <br/> </Application> <br/>
CSFile Content
Private void createcontainer (Object sender, startupeventargs e) <br/>{< br/> var Container = new unitycontainer () <br/>. addnewextension <enterpriselibrarycoreextension> (); <br/> window1 thewindow = container. resolve <window1> (); <br/> thewindow. show (); <br/>}< br/>