I basically agree with Chris's answer, but I think the configuration files are unclean (especially for Unity), so here you will find a solution that allows you to use the runtime configuration without circular references. We are going to do this using registries.
Create an infrastructure project that will contain IConfigureUnity.
public interface IConfigureUnity { public void Configure(UnityContainer container); }
Each of your class library projects will be responsible for implementing this interface to register its own classes.
public class RegistryForSomeClassLibrary : IConfigureUnity { public void Configure(UnityContainer container) { container .RegisterType<IObjectContext, ObjectContextAdapter>() .RegisterType<IConnectionStringProvider, ConnectionStringProvider>() .RegisterType(typeof(IRepository<>), typeof(Repository<>)); } }
Then in your WPF project you need to create a container and apply these registries.
var container = new UnityContainer(); new RegistryForSomeClassLibrary().Configure(container); new RegistryForAnotherClassLibrary().Configure(container);
You now have a fully configured container instance without any configuration files.
Ryan
source share