I'm attempting to use Unity for the first time and I think I might have bitten off more than I can chew. We have a n-tier application that has a base library with several abstract types and then several business scenario specific libraries on top of it w/ concrete types. For ex: The abstract type lead has two implementations, one in a NewAutomotiveLibrary called NewAutomotiveLead and one in an AutomotiveFinanceLibrary called AutomotiveFinanceLead. Within the base library we have a set of adapters that perform logic on the base types like Lead.
I'm trying to use Unity for the first time to return an interface ILeadDuplication that when resolved, returns either an instance of NewAutomotiveLeadDuplication or AutomotiveFinanceLeadDuplication when I called resolve on ILeadDuplication and pass either a string value of either "NewAutomotive" or "AutomotiveFinance" (names mapped when RegisterType was called on the container). Like so:
using (IUnityContainer container = new UnityContainer())
{
container
.RegisterType<ILeadDuplication, AutomotiveFinanceLeadDuplication>("AutomotiveFinance")
.RegisterType<ILeadDuplication, NewAutomotiveLeadDuplication>("NewAutomotive");
ILeadDuplication dupe = container.Resolve<ILeadDuplication>("AutomotiveFinance");
Console.WriteLine(dupe.Created);
}
NOTE: This is for illustration, because the library doesn't know anything about the concreate classes for ILeadDuplication the actually registration would need to be done in the config file.
While this all works great, I need to take it a step further. When calling resolve, I need to be able to pass in an argument of type Lead which is the base type for either NewAutomotiveLead or AutomotiveFinanceLead.
I need to know if it's possible that Unity somehow magically look a property specific to the concrete instance AutomotiveFinanceLead such as "GrossMonthlyIncome" that doesn't exist on Lead and assign it to a new created AutomotiveFinanceLeadDuplication instances property GrossMonthlyIncome.
I'd effectively like to be able to perform a generic set of logic against instances of ILeadDuplication in the base library even thought the instances being generated and properties being mapped are unfamiliar to it.
Thanks!