Jun 5, 2009 at 5:37 PM
Edited Jun 5, 2009 at 5:44 PM
I'm new to Unity, and have had success with my initial simple IOC activites. Now I'm trying to wire up a Database object from the Data Access Application Block into a DAO implementation I have, using XML config. This is with Unity 1.2 and MEL
4.1. I found a blog and an MSDN link on how to wire this up with code, but can't find a good example of what to do in XML. I've added the requisite extension tags, which seem to be fine:
<extensions> <add type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity.EnterpriseLibraryCoreExtension, Microsoft.Practices.EnterpriseLibrary.Common" /><add type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.Unity.DataAccessBlockExtension,
A database named "SomeDB" has been defined using the MEL GUI in web.config (valid connect string, Oracle ODP.Net provider). So now I want a Database object injected into my DAO that uses this "SomeDB" connection string and
provider configuration from DAB. The DAO class takes a Database object as a constructor arg, so constructor injection was used. I tried this type def:
<type type="ISomeDAO" mapTo="SomeDaoImpl" name="DabDaoImpl"> <lifetime type="singleton" /><typeConfig><constructor><param name="database" parameterType="Database"><dependency
The idea was that I'd configure the appDb mapping next for the
Microsoft.Practices.EnterpriseLibrary.Data.Database type, which is where I get confused. In DAB there is a static DatabaseFactory class that offers
a CreateDatabase() method which would be fine in code, but I can't use from Unity config as far as I can tell. So am I stuck with code to do this? I looked at the Database class constructors, but only saw a method signature that takes a string
and a provider factory object. I was hoping the DataAccessBlockExtension support would handle this sort of thing, and so concluded I'm probably doing something wrong.
So, is the above approach right to start with? Should I be wiring in a Database object? If so, how can I define one in XML to be injected, using the
named configuration in the DAB config?
Searching on this topic has come up empty, and I'd like to know if I'm stuck with code in this case, or if there's a way to do this wiring in configuration.
This MSDN link makes it sound like I should be able to do what I'm after, after it shows how dto do the code-based approach, but doesn't say how to do it from config.
Thanks in advance for any tips.