1 / 37

Doing Something Useful with Enterprise Library 3.0

Doing Something Useful with Enterprise Library 3.0. Benjamin Day. Level : Intermediate. About the speaker. Owner, Benjamin Day Consulting, Inc. Email: benday@benday.com Web: http://www.benday.com Blog: http://blog.benday.com Trainer Visual Studio Team System, Team Foundation Server

kimama
Download Presentation

Doing Something Useful with Enterprise Library 3.0

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Doing Something Usefulwith Enterprise Library 3.0 Benjamin Day Level: Intermediate

  2. About the speaker • Owner, Benjamin Day Consulting, Inc. • Email: benday@benday.com • Web: http://www.benday.com • Blog: http://blog.benday.com • Trainer • Visual Studio Team System, Team Foundation Server • Microsoft MVP for C# • Microsoft VSTS/TFS Customer Advisory Council • Leader of Beantown.NET INETA User Group

  3. Agenda • Overview • Policy Injection • Logging • Exception Handling • Validation

  4. Why Enterprise Library? • Why not? • Why write and re-write common application code? • Focus on solving the core business problem • Microsoft solved it for you • Standardized solution • Hooks in nicely with .NET through configs • It’s free • http://codeplex.com/entlib

  5. Plug-in Config Helpers & Design Instrumen-tation ObjectBuilder Ent Lib 3.0 – Application Blocks Data Access Logging Caching Core Cryptography Exception Handling Security Policy Injection Validation http://tinyurl.com/3d8xfw

  6. Data Access Block • Wraps common actions for database access • Handles closing of connections, IDispose calls • Some degree of database independence • Relatively easy to understand

  7. Adopting Enterprise Library • Why is this talk titled“Doing Something Useful…”? • Can be like swimming in the Atlantic at low tide in the spring • What does this have to do with the Data Access Block? • Does it have to be so difficult?

  8. My $0.02 on where begin • Start with the Policy Injection Block • Allows you to defer decisions on other blocks • Configure PIB to use logging • Simple way to debug your configuration • Exception Handling Block • (eat your vegetables) • Caching • Fix performance problems

  9. Policy Injection Block • Uses magic • Mostly elves • Some wood nymphs for reliability • Just kidding.

  10. Policy Injection Block • Layer of abstraction • Lets you hook functionality in at runtime via config • Intercepts calls in to an object’s methods • Think aspect-oriented programming or dependency injection for methods

  11. The Overall Design

  12. Getting started with the PI block • Two ways to use Policy Injection: • Objects extend from MarshalByRef • Code against interfaces instead of concrete classes • Add references • Microsoft.Practices.EnterpriseLibrary.PolicyInjection • Microsoft.Practices.ObjectBuilder • Microsoft.Practices.EnterpriseLibrary.CallHandlers • Plus, whatever block you’ll reference from PI • Edit app.config/web.config with EntLibConfig.exe

  13. Calling into the PI framework • Call PolicyInjection.Create<T>() or one of the overloads • Returns a wrapper to your object • Call your methods through the wrapper

  14. Configuration • EntLibConfig.exe • Uses the Remoting Policy Injector • Policy consists of • Matching Rules • Handlers

  15. Matching Rules • Tells the framework when to run the policy

  16. Handlers • Tells the framework what to do when it finds a policy match

  17. Logging Handler • Through policy injection framework, intercepts calls • Writes message to log before and/or after

  18. Logging Application Block • Logs activity in your app • Trace Listeners • Where does it get stored? • Formatters • How does it get stored? • Filters • What to write?

  19. Logging Block Design

  20. Trace Listeners

  21. Formatters

  22. Demo • Add Policy Injection to an existing app • Configure logging

  23. Exception Handling Block • Allows you to define how to treat exceptions • Option: Catch and re-throw different exception • Option: Eat the exception

  24. Design of the Exception Block

  25. Demo • Add exception handling to our app via Policy Injection • Wrap Handlers • Replace Handlers

  26. Demo • Add Exception Handling to a WCF application

  27. The Validation Block

  28. About the Validation Block • Allows you to validate access to your objects • Validation logic can be stored outside of your objects in the configs • Validation can also be defined via attributes • Similar to a rules engine • Think Windows Workflow Rules “light”

  29. Available Validators • And Composite • Contains Characters • Date Time Range • Domain • Enum Conversion • Not Null • Object Collection • Object Validator • Or Composite • Property Compare • Range Validator • RegEx • Relative Date Time • String Length • Type Conversion

  30. Common Validator Fields • MessageTemplate • Provides a human-readable error message • Overrides the default implementation • MessageTemplateResourceName • Enables messages in resource files • MessageTemplateResourceType • Negate • If statement evaluates to true  rule fails • false  succeeds • Tag • Category for the validation

  31. Message Template Tokens • Think String.Format() • Use these to create custom messages • {0} • Original value being validated • {1} • “Key” for the value • If property or field  name (m_id or Id) • If object  null • {2} • The tag value if available

  32. Service Layer Pattern “Defines an application’s boundary with a layer of services that establishes a set of available operations and coordinates the application’s response in each operation.” -Randy Stafford From “Patterns Of Enterprise Application Architecture”by Martin Fowler, Randy Stafford, et al.Chapter 9

  33. Demo • Validate Restaurant with the ValidationFactory

  34. The Caching Block • Allows you to cache return values from method, properties • Easy to add with the Policy Injection Block

  35. Demo • Populate list of states using the caching block

  36. Summary • Policy Injection Block Helps Speed Adoption • Logging Block • Exception Handling Block • Exception Handling in WCF • Validation Block • Caching Block

  37. About the speaker • Owner, Benjamin Day Consulting, Inc. • Email: benday@benday.com • Web: http://www.benday.com • Blog: http://blog.benday.com • Trainer • Visual Studio Team System, Team Foundation Server • Microsoft MVP for C# • Microsoft VSTS/TFS Customer Advisory Council • Leader of Beantown.NET INETA User Group

More Related