Apr 3, 2012 at 3:28 PM
Edited Apr 3, 2012 at 3:30 PM
DatabaseFactory.CreateDatabase() and EnterpriseLibraryContainer.Current.GetInstance() are functionally equivalent so you can use both methods. I.e. CreateDatabase() actually calls GetInstance<Database>(). (The only difference being that
CreateDatabase potentially logs a message in the case of an exception.)
But as described in Creating and Referencing Enterprise Library Objects: "legacy static facades and factories that were the
default approach in versions of Enterprise Library prior to version 5.0 are still available, and continue to be supported for the purpose of backwards compatibility. However, new code should use either the service locator approach or the techniques for accessing
the container directly, as described in previous sections of this topic". So, the preferred method in Enterprise Library 5 is to use the service locator or dependency injection approach.
> remove line objDb = null from finally block
In general, you should not set local variables to null -- there is rarely a need since .NET will manage that for you. See Should
I assign null to my local variables?
Enterprise Library support engineer