У меня есть веб-приложение asp.net mvc 3, в котором есть сборки плагинов, реализующие зависящие от системы контексты и службы EF.
Например, у меня есть сборка, которая в целом выглядит следующим образом:
System1Controller : IController // from System.Web.Mvc
ISystem1Service {
IList<System1Type> GetOperation(string something);
}
System1Service : ISystem1Service
{
private ISystem1Entities context;
public System1Service(ISystem1Entities context)
{
this.context = context;
}
}
ISystem1Entities
{
IDbSet<System1Type> Operations { get; set; }
}
System1Entities : DbContext, ISystem1Entities
Использование Unity Bootstrapper и вызов Bootstrapper.Initialize() работает со следующей реализацией BuildUnityContainer()
private static IUnityContainer BuildUnityContainer()
{
var theContainer = new UnityContainer();
var connectionString = ConfigurationManager.ConnectionStrings["WebAppConnectionString"];
if (connectionString == null)
{
throw new ApplicationException("The ConnectionString is not defined.");
}
// register all your components with the container here
// it is NOT necessary to register your controllers
theContainer.RegisterType<ISystem1Entities, System1Entities>(
new HierarchicalLifetimeManager(),
new InjectionConstructor(connectionString.ConnectionString));
theContainer.RegisterType<ISystem1Service, System1Service>();
var factory = new UnityControllerFactory(theContainer);
ControllerBuilder.Current.SetControllerFactory(factory);
return theContainer;
}
Я хочу реорганизовать загрузчик, чтобы я мог загружать «неизвестные» сборки во время компиляции, регистрировать содержащиеся в них типы и позволять веб-приложению ссылаться на контроллер, службы и контексты по мере необходимости.
Я просмотрел проект Unity AutoRegistraion, и, похоже, он приближает меня к реализации, которую я хочу, но не знаю, как реализовать следующую идею:
BootStrapper.BuildUnityConfiguration
Initialize Container
RegisterMyAssemblies()
Я хочу, чтобы процесс «RegisterMyAssemblies» зарегистрировал список подстановочных знаков сборок, а затем приступил к регистрации типов в каждой отдельной сборке. Какие-либо предложения?