Enterprise Library for  .NET Framework 2.0: Core Architecture
Enterprise Library for .NET Framework 2.0 <ul><li>Major new release of Enterprise Library </li></ul><ul><li>Designed for M...
Key Changes from Enterprise Library 1.x <ul><li>Configuration now built on System.Configuration </li></ul><ul><ul><li>Conf...
Enterprise Library for .NET Framework 2.0 Caching Security Data  Access Logging Exception Handling Cryptography Core Block...
Enterprise Library for .NET Framework 2.0 Caching Security Data  Access Logging Exception Handling Plug-in Config Helpers ...
Core Architecture <ul><li>Configuration runtime </li></ul><ul><li>Configuration design and tooling </li></ul><ul><li>Instr...
Configuration in Enterprise Library <ul><li>All Enterprise Library blocks are configurable </li></ul><ul><ul><li>Controls ...
System.Configuration in .NET 2.0 <ul><li>Much more powerful than the Microsoft® .NET Framework 1.x classes </li></ul><ul><...
Configuration Runtime <ul><li>Enterprise Library for .NET Framework 2.0 uses System.Configuration, but provides additional...
Configuration Sources Application Blocks or Custom Code IConfigurationSource SystemConfiguration Source FileConfiguration ...
Configuration Sources <ul><li>Abstract interface that supports loading/saving configuration and monitoring for changes </l...
Choosing a Configuration Source <ul><li>Several ways of choosing a configuration source when using Enterprise Library </li...
Configuration Source Examples <ul><li>// Use default source specified in the app.config / web.config file </li></ul><ul><l...
Change Notifications <ul><li>IConfigurationSource supports monitoring configuration data for changes </li></ul><ul><ul><li...
Configuration Design and Tooling <ul><li>Configuration tool eliminates the need to edit the blocks’ XML configuration file...
Configuration Design-Time <ul><li>Improved API </li></ul><ul><ul><li>Simple base configuration design manager </li></ul></...
Instrumentation <ul><li>All Enterprise Library blocks include instrumentation to assist in development, testing and operat...
Enabling Instrumentation <ul><li>Run the installer classes to create the instrumentation artifacts: </li></ul><ul><ul><li>...
Instrumentation Architecture <ul><li>Event-driven architecture </li></ul>Instrumentation Provider Class(es) Instrumentatio...
Instrumentation Attributes <ul><li>Instrumentation is wired up using attributes: </li></ul><ul><ul><li>[InstrumentationLis...
Instrumentation Example public class  Database :  IInstrumentationEventProvider  {   DbConnection OpenConnection() { // Do...
Instrumentation Installation Attributes <ul><li>Running installutil over an instrumented class should install all required...
Factories and Object Builder <ul><li>Objects inside application blocks need to be constructed and configured </li></ul><ul...
Object Builder <ul><li>New subsystem shared between EntLib and Composite UI Application Block </li></ul><ul><li>Responsibl...
Factories Core Application Block Static Factory or façade Instance  Provider Factory Enterprise Library Factory Custom Fac...
Using Static Facades and Factories <ul><li>Easiest way to use the blocks </li></ul><ul><li>Configuration is retrieved from...
Using Instance Provider Factories <ul><li>You get slightly more control on how objects are created </li></ul><ul><li>You c...
Creating Objects Directly <ul><li>New up the object and any dependent objects yourself </li></ul><ul><li>Configuration sou...
Resources  <ul><li>Download Enterprise Library and related resources from: </li></ul><ul><ul><li>http://msdn.microsoft.com...
 
Upcoming SlideShare
Loading in …5
×

Enterprise Library 2.0 Core Architecture

3,435 views

Published on

From the P&P website

Published in: Business, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,435
On SlideShare
0
From Embeds
0
Number of Embeds
35
Actions
Shares
0
Downloads
119
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Enterprise Library 2.0 Core Architecture

    1. 1. Enterprise Library for .NET Framework 2.0: Core Architecture
    2. 2. Enterprise Library for .NET Framework 2.0 <ul><li>Major new release of Enterprise Library </li></ul><ul><li>Designed for Microsoft® .NET Framework 2.0 </li></ul><ul><ul><li>Leverages key new capabilities provided by the platform </li></ul></ul><ul><ul><li>Certain features from Enterprise Library v1.x have been deprecated in favor of the platform </li></ul></ul><ul><li>Scenarios and features largely unchanged </li></ul><ul><ul><li>Public application programming interfaces (APIs) not identical, but changes are minor </li></ul></ul><ul><ul><li>…but many improvements are hiding under the covers! </li></ul></ul>
    3. 3. Key Changes from Enterprise Library 1.x <ul><li>Configuration now built on System.Configuration </li></ul><ul><ul><li>Configuration Application Block no longer exists </li></ul></ul><ul><ul><li>Easier to use blocks with or without configuration files </li></ul></ul><ul><li>Instrumentation configurable and disabled by default </li></ul><ul><li>Much improved Logging Application Block </li></ul><ul><ul><li>Flexibility and performance </li></ul></ul><ul><li>Simpler and more powerful Data Access Application Block </li></ul><ul><ul><li>Use with OLE-DB, Open Database Connectivity (ODBC) or any managed provider </li></ul></ul><ul><li>Most of the Security Application Block has been removed </li></ul><ul><ul><li>Deprecated in favor of .NET Membership and Profile features </li></ul></ul>
    4. 4. Enterprise Library for .NET Framework 2.0 Caching Security Data Access Logging Exception Handling Cryptography Core Block Dependency Optional Provider Dependency Plug-in Config Helpers & Design Instrumen- tation Object Builder
    5. 5. Enterprise Library for .NET Framework 2.0 Caching Security Data Access Logging Exception Handling Plug-in Config Helpers & Design Instrumen- tation Object Builder Cryptography Core Block Dependency Optional Provider Dependency
    6. 6. Core Architecture <ul><li>Configuration runtime </li></ul><ul><li>Configuration design and tooling </li></ul><ul><li>Instrumentation </li></ul><ul><li>Factories and object builder </li></ul>
    7. 7. Configuration in Enterprise Library <ul><li>All Enterprise Library blocks are configurable </li></ul><ul><ul><li>Controls how the blocks work in your application </li></ul></ul><ul><ul><li>Specifies which plug-ins you are using </li></ul></ul><ul><li>Previous versions of Enterprise Library included a Configuration Application Block </li></ul><ul><ul><li>Supported reading/writing complex configuration objects from pluggable storage </li></ul></ul><ul><ul><li>Used by all Enterprise Library blocks, and can be used by customer code </li></ul></ul><ul><li>In Enterprise Library for .NET Framework 2.0, the requirements are the same but the solution is different </li></ul>
    8. 8. System.Configuration in .NET 2.0 <ul><li>Much more powerful than the Microsoft® .NET Framework 1.x classes </li></ul><ul><ul><li>Supports reading and writing rich graphs of objects </li></ul></ul><ul><ul><li>Automatic serialization and deserialization between configuration classes and XML using ConfigurationSection and ConfigurationElement </li></ul></ul><ul><li>Some Enterprise Library 1.x features are not directly supported </li></ul><ul><ul><li>Storing configuration somewhere other than XML Files </li></ul></ul><ul><ul><li>Monitoring external changes to configuration </li></ul></ul>
    9. 9. Configuration Runtime <ul><li>Enterprise Library for .NET Framework 2.0 uses System.Configuration, but provides additional helper classes to provide more functionality </li></ul><ul><ul><li>All blocks provide ConfigurationSections which are stored in app.config / web.config by default </li></ul></ul><ul><ul><li>All System.Configuration features such as encryption and using external files are supported </li></ul></ul><ul><li>Configuration Runtime helper classes are in the Common assembly </li></ul><ul><ul><li>Used by all Enterprise Library application blocks </li></ul></ul><ul><ul><li>Can be used by your apps, but you generally won’t need to </li></ul></ul>
    10. 10. Configuration Sources Application Blocks or Custom Code IConfigurationSource SystemConfiguration Source FileConfiguration Source SqlConfiguration Source app.config / web.config foo.config app.config / web.config Default ConfigurationSource = … System.Configuration File Watcher File Watcher
    11. 11. Configuration Sources <ul><li>Abstract interface that supports loading/saving configuration and monitoring for changes </li></ul><ul><li>Two implementations included in the core </li></ul><ul><ul><li>SystemConfigurationSource defers to System.Configuration to read from default configuration file (plus adds file watchers) </li></ul></ul><ul><ul><li>FileConfigurationSource defers to System.Configuration but reads from arbitrary files </li></ul></ul><ul><li>SqlConfigurationSource included as a sample </li></ul><ul><ul><li>Requires that sections derive from SerializableConfigurationSection </li></ul></ul>
    12. 12. Choosing a Configuration Source <ul><li>Several ways of choosing a configuration source when using Enterprise Library </li></ul><ul><li>If you access blocks using static façades or factories (Examples: DatabaseFactory, Logger), you will always use the application’s default ConfigurationSource: </li></ul><ul><ul><li>If you define a ConfigurationSources section in your default.config file, you can specify which type of source should be used </li></ul></ul><ul><ul><li>If you don’t have this section, SystemConfigurationSource is used </li></ul></ul><ul><li>If you use the instance factories (Examples:DatabaseProviderFactory, LogWriterFactory) you can specify a configuration source of your choosing </li></ul><ul><ul><li>Instantiated directly or using ConfigurationSourceFactory </li></ul></ul>
    13. 13. Configuration Source Examples <ul><li>// Use default source specified in the app.config / web.config file </li></ul><ul><li>Database db1 = DatabaseFactory.CreateDatabase(“Sales”); </li></ul><ul><li>// Use the specified source – you don’t need an app.config / web.config file </li></ul><ul><li>FileConfigurationSource fileSource = new FileConfigurationSource(“tom.config”); </li></ul><ul><li>DatabaseProviderFactory factory = new DatabaseProviderFactory(fileSource); </li></ul><ul><li>Database db2 = factory.Create(“Sales”); </li></ul>< enterpriseLibrary.ConfigurationSource selectedSource =&quot;fileSource&quot;> < sources > < add name =&quot;fileSource&quot; type =&quot;Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common&quot; filePath =&quot;test.config&quot;/> < add name =&quot;systemSource&quot; type =&quot;Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common&quot;/> </ sources > </ enterpriseLibrary.ConfigurationSource >
    14. 14. Change Notifications <ul><li>IConfigurationSource supports monitoring configuration data for changes </li></ul><ul><ul><li>AddSectionHandler(string sectionName, ConfigurationChangedEventHandler handler ) </li></ul></ul><ul><ul><li>RemoveSectionHandler(string sectionName, ConfigurationChangedEventHandler handler ) </li></ul></ul><ul><li>Any code can register for changes and respond accordingly </li></ul><ul><li>In Enterprise Library, only the Logging Application Block currently registers to receive change notification events </li></ul>
    15. 15. Configuration Design and Tooling <ul><li>Configuration tool eliminates the need to edit the blocks’ XML configuration files </li></ul><ul><ul><li>Quickly add default configuration for a block </li></ul></ul><ul><ul><li>Strongly-typed properties and providers </li></ul></ul><ul><ul><li>Validate configuration before you save </li></ul></ul><ul><li>No major changes to configuration tool user experience from previous versions of Enterprise Library </li></ul><ul><li>Configuration design-time subsystem can be used in your own applications and blocks to provide a similar experience for your users </li></ul>
    16. 16. Configuration Design-Time <ul><li>Improved API </li></ul><ul><ul><li>Simple base configuration design manager </li></ul></ul><ul><ul><li>Better node registration and command registration </li></ul></ul><ul><ul><li>3 to 4 simple classes to register your custom provider </li></ul></ul><ul><ul><li>No more OnSited  </li></ul></ul><ul><li>One configuration design manager per section </li></ul><ul><li>Dependent configuration design managers </li></ul><ul><li>Easy to interop with any .NET configuration </li></ul>
    17. 17. Instrumentation <ul><li>All Enterprise Library blocks include instrumentation to assist in development, testing and operations </li></ul><ul><ul><li>Event Log events </li></ul></ul><ul><ul><li>Performance Counters </li></ul></ul><ul><ul><li>Microsoft® Windows® Management Instrumentation (WMI) events </li></ul></ul><ul><li>All instrumentation is disabled by default, but each type can be individually enabled using the configuration tool </li></ul><ul><li>Instrumentation code contained in common assembly can be reused in your apps </li></ul>
    18. 18. Enabling Instrumentation <ul><li>Run the installer classes to create the instrumentation artifacts: </li></ul><ul><ul><li>Run installservices.bat (using an admin account), or </li></ul></ul><ul><ul><li>Run installutil.exe over each Enterprise Library assembly (using an admin account), or </li></ul></ul><ul><ul><li>Create your own installers/MSI that do this </li></ul></ul><ul><li>Configure instrumentation for your app using the tool </li></ul>
    19. 19. Instrumentation Architecture <ul><li>Event-driven architecture </li></ul>Instrumentation Provider Class(es) Instrumentation Listener Class(es) Instrumentation Configuration Settings WMI Perf Counters Event Log Event ObjectBuilder Wires up Application or Block calls
    20. 20. Instrumentation Attributes <ul><li>Instrumentation is wired up using attributes: </li></ul><ul><ul><li>[InstrumentationListener] </li></ul></ul><ul><ul><ul><li>Defined on a type within the block or application </li></ul></ul></ul><ul><ul><ul><li>Specifies which listener will deal with instrumentation events </li></ul></ul></ul><ul><ul><li>[InstrumentationProvider] </li></ul></ul><ul><ul><ul><li>Defined on an event within the block or application </li></ul></ul></ul><ul><ul><ul><li>Specifies the name of the event being fired </li></ul></ul></ul><ul><ul><li>[InstrumentationConsumer] </li></ul></ul><ul><ul><ul><li>Defined on a method within the instrumentation listener </li></ul></ul></ul><ul><ul><ul><li>The method contains the instrumentation logic, and the name must match the one used in an [InstrumentationProvider] declaration </li></ul></ul></ul>
    21. 21. Instrumentation Example public class Database : IInstrumentationEventProvider { DbConnection OpenConnection() { // Do stuff instrumentationProvider.FireConnectionOpenedEvent(); } public object GetInstrumentationEventProvider() { return instrumentationProvider; } } [InstrumentationListener( typeof(DataInstrumentationListener), typeof(DataInstrumentationListenerBinder))] public class DataInstrumentationProvider { [InstrumentationProvider(&quot;ConnectionOpened&quot;)] public event E ventHandler<EventArgs> connectionOpened; public void FireConnectionOpenedEvent() { connectionOpened(this, new EventArgs()); } internal class DataInstrumentationListener : InstrumentationListener { public DataInstrumentationListener(string instanceName, bool perfCountersEnabled, bool eventLogEnabled, bool wmiEnabled) : base(perf…, event…, wmi…) {} [InstrumentationConsumer( “ConnectionOpened&quot;)] public void ConnectionOpened(object sender, EventArgs e) { if (PerformanceCountersEnabled) connectionOpenedCounter.Increment(); }
    22. 22. Instrumentation Installation Attributes <ul><li>Running installutil over an instrumented class should install all required event log sources, WMI schemas and performance counters </li></ul><ul><li>Enterprise Library provides a ReflectionInstaller which uses reflection to find these, with the help of some attributes </li></ul><ul><li>[HasInstallableResources] </li></ul><ul><ul><li>Indicates that there is instrumentation to install </li></ul></ul><ul><li>[PerformanceCountersDefinition] </li></ul><ul><ul><li>Defines the counters used by the block or app </li></ul></ul><ul><li>[EventLogDefinition] </li></ul><ul><ul><li>Defines the event log sources used by the block or app </li></ul></ul>
    23. 23. Factories and Object Builder <ul><li>Objects inside application blocks need to be constructed and configured </li></ul><ul><li>There are different ways you can construct objects depending on what you want to do </li></ul><ul><ul><li>Use a default configuration source </li></ul></ul><ul><ul><li>Use a custom configuration source </li></ul></ul><ul><ul><li>Don’t use any configuration at all </li></ul></ul><ul><ul><li>Inject instrumentation </li></ul></ul><ul><li>Although each block is different, all rely on similar types of factories for construction </li></ul>
    24. 24. Object Builder <ul><li>New subsystem shared between EntLib and Composite UI Application Block </li></ul><ul><li>Responsible for building objects inside the application blocks </li></ul><ul><ul><li>Invoking the necessary custom factory using data from configuration </li></ul></ul><ul><ul><li>Configuring instrumentation for the blocks </li></ul></ul><ul><li>Can be leveraged from your own apps, but understanding ObjectBuilder is not required to use Enterprise Library </li></ul>
    25. 25. Factories Core Application Block Static Factory or façade Instance Provider Factory Enterprise Library Factory Custom Factory Block Objects Object Builder Strategies User Code Configuration Source
    26. 26. Using Static Facades and Factories <ul><li>Easiest way to use the blocks </li></ul><ul><li>Configuration is retrieved from the default configuration source </li></ul><ul><li>Instrumentation is wired up (but may be disabled) </li></ul><ul><li>Results in a call to an instance factory behind the scenes </li></ul><ul><li>Examples: </li></ul><ul><ul><li>Dim db As Database = DatabaseFactory.CreateDatabase(“Sales”) </li></ul></ul><ul><ul><li>Logger.Write(“My message”, “My Category”) </li></ul></ul>
    27. 27. Using Instance Provider Factories <ul><li>You get slightly more control on how objects are created </li></ul><ul><li>You can choose your own configuration source </li></ul><ul><li>Instrumentation is wired up (but may be disabled) </li></ul><ul><li>Examples: </li></ul><ul><ul><li>Dim factory As New DatabaseProviderFactory(configSource) Dim db As Database = factory.Create(“Sales”) </li></ul></ul><ul><ul><li>Dim factory As New LogWriterFactory(configSource) Dim writer As LogWriter = factory.Create() </li></ul></ul>
    28. 28. Creating Objects Directly <ul><li>New up the object and any dependent objects yourself </li></ul><ul><li>Configuration sources are not used </li></ul><ul><li>Object Builder is not involved </li></ul><ul><li>Instrumentation will not be automatically wired up (but you can add it yourself) </li></ul><ul><li>Example: </li></ul><ul><ul><li>Dim db As SqlDatabase = New SqlDatabase(&quot;server=(local)SQLEXPRESS;database=EntLibQuickStarts;Integrated Security=true&quot;) </li></ul></ul>
    29. 29. Resources <ul><li>Download Enterprise Library and related resources from: </li></ul><ul><ul><li>http://msdn.microsoft.com/practices </li></ul></ul><ul><li>Join the Enterprise Library Community at: </li></ul><ul><ul><li>http://practices.gotdotnet.com/projects/entlib </li></ul></ul><ul><li>Read blogs from the Enterprise Library team at: </li></ul><ul><ul><li>http:// msdn.microsoft.com/practices/Comm/EntLibBlogs / </li></ul></ul>

    ×