コントローラを登録するためのAddin DefaultController Factoryを試してください。 スリーステップ:ステップ1 1.Addプロジェクト
public class ControllerFactory :DefaultControllerFactory
{
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
try
{
if (controllerType == null)
throw new ArgumentNullException("controllerType");
if (!typeof(IController).IsAssignableFrom(controllerType))
throw new ArgumentException(string.Format(
"Type requested is not a controller: {0}",
controllerType.Name),
"controllerType");
return MvcUnityContainer.Container.Resolve(controllerType) as IController;
}
catch
{
return null;
}
}
public static class MvcUnityContainer
{
public static UnityContainer Container { get; set; }
}
}
ステップ2のクラスDefaultControllerFactory:ステップ3
private static IUnityContainer BuildUnityContainer()
{
var container = new UnityContainer();
// register all your components with the container here
// it is NOT necessary to register your controllers
// e.g. container.RegisterType<ITestService, TestService>();
//RegisterTypes(container);
container = new UnityContainer();
container.RegisterType<IProductRepository, ProductRepository>();
UnityInterceptionExample.Models.ControllerFactory.MvcUnityContainer.Container = container;
return container;
}
BuildUnityContainer方法でブートストラップクラスでそれを登録しますし、グローバルに登録.asaxファイル
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
Bootstrapper.Initialise();
ControllerBuilder.Current.SetControllerFactory(typeof(ControllerFactory));
}
そしてfinisihed。 これはあなたのために働くかもしれません... ハッピーコーディング。
[編集ヘルプ](http://stackoverflow.com/editing-help#code)をお読みください。 –
'コンテナ'のタイプは? –
また、 'PopupCommand'はそのコンストラクタでどのような引数をとりますか?例外にはさらに情報が含まれていますか? –