2010-05-11 3 views
0

내 프로젝트에서 나는 Autofac을 사용하고있다. 이전에는 괜찮 았어. 이제 Autofac에 새로운 코드를 추가했는데 "작성 대리자가 null을 반환하지 않아야합니다."오류가 발생했습니다. 내가 TestPermissionHelper를 해결하고 Applicaiton_PostAuthenticate() 방법에서는 Global.asax에서 지금오류 : 생성 대리자가 Autofac에서 null을 반환하지 않아야합니까?

builder.Register<Rep>(c => { 
             /*Get Session and LoginId*/ 

           return session.CreateQuery(@"from Rep where LoginId='" + 
                LoginId+ "'").List<Rep>(). 
                FirstOrDefault() ?? new Rep(); 
          }); 
builder.Register<TestPermissionHelper>(); 

다음과 같이 내가 만든

변경입니다.

재미있는 점은 내가 로그인 페이지를 때리면 오류가 발생한다는 것입니다. 그렇지 않으면 정상적으로 작동합니다.

이 작은 코드에서 전체 그림을 이해하는 것이 어렵다는 것을 알고 있습니다. 누군가가 적어도이 유형의 오류에 대한 가능한 이유가 무엇인지 말해 줄 수 있다면 좋을 것입니다.

감사

참고 :이 도움이 될 수 있다면, 나는 또한 오류의 스택 추적을 제공하고

Stack trace: at Autofac.Component.Activation.DelegateActivator.ActivateInstance(IContext context, IEnumerable`1 parameters) 
    at Autofac.Component.Registration.ResolveInstance(IContext context, IEnumerable`1 parameters, IDisposer disposer, Boolean& newInstance) 
    at Autofac.Context.TryResolve(Service service, Object& instance, IEnumerable`1 parameters) 
    at Autofac.Context.Resolve(Service service, IEnumerable`1 parameters) 
    at Autofac.Context.Resolve(Type serviceType, IEnumerable`1 parameters) 
    at Autofac.Component.Activation.AutowiringParameter.<>c__DisplayClass2.<CanSupplyValue>b__0() 
    at Autofac.Component.Activation.DirectConstructorInvoker.<InvokeConstructor>b__0(Func`1 pa) 
    at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext() 
    at System.Linq.Buffer`1..ctor(IEnumerable`1 source) 
    at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) 
    at Autofac.Component.Activation.DirectConstructorInvoker.InvokeConstructor(IContext context, IEnumerable`1 parameters, ConstructorInfo ci, Func`1[] args) 
    at Autofac.Component.Activation.ReflectionActivator.ConstructInstance(ConstructorInfo ci, IContext context, IEnumerable`1 parameters, Func`1[] parameterAccessors) 
    at Autofac.Component.Activation.ReflectionActivator.ActivateInstance(IContext context, IEnumerable`1 parameters) 
    at Autofac.Component.Registration.ResolveInstance(IContext context, IEnumerable`1 parameters, IDisposer disposer, Boolean& newInstance) 
    at Autofac.Context.TryResolve(Service service, Object& instance, IEnumerable`1 parameters) 
    at Autofac.Context.Resolve(Service service, IEnumerable`1 parameters) 
    at Autofac.Context.Resolve(Type serviceType, IEnumerable`1 parameters) 
    at Autofac.Context.Resolve[TService](IEnumerable`1 parameters) 
    at Autofac.Context.Resolve[TService](Parameter[] parameters) 
    at Autofac.Container.Resolve[TService](Parameter[] parameters) 

답변

0

문제의 근본 원인이 Autofac에없는 것 같습니다. Rep 테이블에 로그인 ID에 대한 항목이없는 경우 새 Rep 개체를 만듭니다. If가 다른 구성 요소의 종속성으로 사용되면 Rep 객체의 인스턴스화되지 않은 참조 속성을 참조하지 않아야합니다.

+0

그래, 문제는 제가 Rep의 등록 정보에 액세스 했으므로 null 이었기 때문에 오류가 발생했습니다. – Bipul

0

코드는 충분 보인다 대리인 등록 이제까지 null을 반환 어떻게 볼 수 없습니다 어떤 오류가 발생하지 않는 한.

Rep 등록에서 다양한 반환 값 (null 포함)을 사용하여 TestPermissionHelper을 해결하려고하는 일부 단위 테스트를 작성하는 것이 좋습니다. 다행스럽게도 오류를 재현하고 오류가 발생한 상태를 격리 할 수 ​​있기를 바랍니다.

관련 문제