我正在开发一个 asp.net mvc 4 站点,使用 Simple Injector 作为 Ioc 工具。这将是一个可插拔的架构。一些控制器和视图在另一个程序集中(另一个 mvc4 应用程序,Plugin.Web.dll)。从主应用程序中,我知道 Plugin.Web.dll 的路径,加载插件。
container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
container.RegisterMvcAttributeFilterProvider();
container.Options.AllowOverridingRegistrations = true;
var appPath = AppDomain.CurrentDomain.BaseDirectory;
string[] files = Directory.GetFiles(appPath + "\\Plugins", "*",
SearchOption.AllDirectories);
foreach (var fileName in files)
{
Console.WriteLine(fileName);
var assembly = Assembly.LoadFrom(fileName);
container.RegisterMvcControllers(assembly);
var controllerTypes =
from type in assembly.GetExportedTypes()
where type.Name.EndsWith("Controller",
StringComparison.Ordinal)
where typeof(IController).IsAssignableFrom(type)
where !type.IsAbstract
select type;
// Instead of verify:
foreach (var type in controllerTypes)
{
container.GetInstance(type);
}
}
container.Options.AllowOverridingRegistrations = false;
container.Verify();
DependencyResolver.SetResolver(
new SimpleInjectorDependencyResolver(container));
它没有给出任何错误。
但是当我点击这个点击时,在视图中:
@Html.ActionLink("plugin page","PluginPage","Plugin")
它给出“找不到资源。,http 404”
提前致谢