종속성 해결 프로그램으로 다음 클래스를 사용하고 있습니다. 나는 다음과 같은 몇 가지 오류를 얻고있다이Unity 및 Web API 컨트롤러가있는 사용자 지정 종속성 해결 프로그램을 사용하는 중 오류가 발생했습니다.
config.DependencyResolver = new UnityWebAPIResolver(UnityConfig.GetContainer());
문제와 같은 의존성 해결 프로그램을 구성하고 경로 설정 후 WebApiConfig 클래스에서 http://www.asp.net/web-api/overview/advanced/dependency-injection
public class UnityWebAPIResolver : IDependencyResolver
{
protected IUnityContainer container;
public UnityWebAPIResolver(IUnityContainer container)
{
if (container == null)
{
throw new ArgumentNullException("container");
}
this.container = container;
}
public object GetService(Type serviceType)
{
try
{
return container.Resolve(serviceType); **// This line throws error**
}
catch (ResolutionFailedException)
{
return null;
}
}
public IEnumerable<object> GetServices(Type serviceType)
{
try
{
return container.ResolveAll(serviceType); **// This line throws error**
}
catch (ResolutionFailedException)
{
return new List<object>();
}
}
public IDependencyScope BeginScope()
{
var child = container.CreateChildContainer();
return new UnityWebAPIResolver(child);
}
public void Dispose()
{
container.Dispose();
}
}
에서 참조를 얻었다 ..
InvalidOperationException - The type IHostBufferPolicySelector does not have an accessible constructor.
InvalidOperationException - The type ModelMetadataProvider does not have an accessible constructor.
InvalidOperationException - The type ITraceManager does not have an accessible constructor.
InvalidOperationException - The type ITraceWriter does not have an accessible constructor.
InvalidOperationException - The type IHttpControllerSelector does not have an accessible constructor.
InvalidOperationException - The type IAssembliesResolver does not have an accessible constructor.
InvalidOperationException - The type IHttpControllerTypeResolver does not have an accessible constructor.
InvalidOperationException - The type IHttpActionSelector does not have an accessible constructor.
InvalidOperationException - The type IActionValueBinder does not have an accessible constructor.
InvalidOperationException - The type IContentNegotiator does not have an accessible constructor.
InvalidOperationException - The type IHttpControllerActivator does not have an accessible constructor.
InvalidOperationException - The type IBodyModelValidator does not have an accessible constructor.
내 global.asax에서 이와 같은 일을하려고해도 같은 오류가 발생합니다.
GlobalConfiguration.Configuration.DependencyResolver = new UnityWebAPIResolver(UnityConfig.GetContainer());
질문 : 내 API 컨트롤러에 모든 의존성이 위 (특정 프레임 워크) 유형을 언급 한 여러 해결할 수 없기 때문에 내 유일한 관심사는, 제대로 주입 될 것으로 보인다 은 기회가있다 그 전체 프레임 워크 오작동을 일으키고 무작위로 오류를 생성 할 수 있습니까?
사용자 정의 유형을 어느 시점에서 매핑해야합니다. 마술처럼 처리되지는 않습니다. 이런 일을하는'Unity.config'가 있습니까? – Haney
예 내 모든 사용자 정의 유형이 매핑되고 내 사용자 정의 유형에 오류가 발생하지 않습니다 ... 단지 컨테이너에 등록되지 않은 MVC 프레임 워크 유형에 대한 오류가 발생합니다 .. – ATHER
아하, 예,이 문제가 다시있었습니다. 하루도. 나는 그것을 고쳤지 만, 어떻게 찾을 수 있는지 내 소스 코드를 봐야 할 것이다. 몇 시간 만 기다려주세요. 답변을 게시 해 드리겠습니다. :) – Haney