1
我有一些問題想簡單的接線噴油器和網頁API服務類型IAssembliesResolver不受支持。參數名:的serviceType
我得到的錯誤是:
服務類型不支持IAssembliesResolver。參數名: 的serviceType
,並拋出由我試圖註冊自帶的集成庫simpleinjector和Web API(的NuGet)擴展方法
控制器時除外
container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
我只是修改了代碼覆蓋IAssemblyResolver,但它不工作
public static void Initialize()
{
GlobalConfiguration.Configuration.Services
.Replace(typeof(IAssembliesResolver),
new CustomAssembliesResolver());
var container = new Container();
InitializeContainer(container);
container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
container.Verify();
GlobalConfiguration.Configuration.DependencyResolver =
new SimpleInjectorWebApiDependencyResolver(container);
}
我把自定義程序集解析器從this question,我只是它指的bin文件夾
public class CustomAssembliesResolver:DefaultAssembliesResolver
{
public override ICollection<Assembly> GetAssemblies()
{
var appPath = AppDomain.CurrentDomain.BaseDirectory;
var plugins = (
from file in Directory.GetFiles(
appPath + "\\bin", "*.dll",
SearchOption.AllDirectories)
let assembly = Assembly.LoadFile(file)
select assembly)
.ToArray();
return base.GetAssemblies()
.Union(plugins).ToArray();
}
}
什麼想法?
UPDATE:
這是堆棧:
[ArgumentException: The service type IAssembliesResolver is not supported.
Parameter name: serviceType]
System.Web.Http.Services.DefaultServices.GetService(Type serviceType) +529
System.Web.Http.ServicesExtensions.GetService(ServicesContainer services) +62
System.Web.Http.ServicesExtensions.GetServiceOrThrow(ServicesContainer services) +60
SimpleInjector.SimpleInjectorWebApiExtensions.RegisterWebApiControllers(Container container, HttpConfiguration configuration) +107
ProjectName.Api.App_Start.SimpleInjectorWebApiInitializer.Initialize() in c:\Users\User\Documents\Visual Studio 2013\Projects\ProjectName.Api\Project.Api\App_Start\SimpleInjectorWebApiInitializer.cs:25
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +229
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +211
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
WebActivator.BaseActivationMethodAttribute.InvokeMethod() +341
WebActivator.ActivationManager.RunActivationMethods() +534
WebActivator.ActivationManager.RunPostStartMethods() +38
WebActivator.StartMethodCallingModule.Init(HttpApplication context) +159
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +530
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475
[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12617364
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12456981
你可以發佈完整的調用堆棧和所有異常信息嗎? – Steven
請檢查我的更新與堆棧,謝謝@Steven –
如果你刪除'.Replace(typeof(IAssembliesResolver),'line?我預計它也會失敗。 – Steven