2011-01-06 3 views
2
에 두 번 바운드되어

나는 우리가 우리의 저장소 및 비즈니스 오브젝트 바인딩 다음 NinjectModule,이 : 우리가 NinjectHttpApplication에서 상속 우리의 Global.asax에서 관련 재정의를하나의 컨트롤러는 때때로 Ninject에

/// <summary> 
/// Used by Ninject to bind interface contracts to concrete types. 
/// </summary> 
public class ServiceModule : NinjectModule 
{ 
    /// <summary> 
    /// Loads this instance. 
    /// </summary> 
    public override void Load() 
    { 
     //bindings here. 
     //Bind<IMyInterface>().To<MyImplementation>(); 
     Bind<IUserRepository>().To<SqlUserRepository>(); 
     Bind<IHomeRepository>().To<SqlHomeRepository>(); 
     Bind<IPhotoRepository>().To<SqlPhotoRepository>(); 
     //and so on 

     //business objects 
     Bind<IUser>().To<Data.User>(); 
     Bind<IHome>().To<Data.Home>(); 
     Bind<IPhoto>().To<Data.Photo>(); 
     //and so on 
    } 
} 

을 그리고 여기를 이제, 모든 일 명을 제외하고 잘 작동

protected override void OnApplicationStarted() 
    { 
     base.OnApplicationStarted(); 

     //routes and areas 
     AreaRegistration.RegisterAllAreas(); 

     RegisterRoutes(RouteTable.Routes); 

     //Initializes a singleton that must reference this HttpApplication class, 
     //in order to provide the Ninject Kernel to the rest of Thing.Web. This 
     //is necessary because there are a few instances (currently Membership) 
     //that require manual dependency injection. 
     NinjectKernel.Instance = new NinjectKernel(this); 

     //view model factory. 
     NinjectKernel.Instance.Kernel.Bind<IModelFactory>().To<MasterModelFactory>(); 
    } 

    protected override NinjectControllerFactory CreateControllerFactory() 
    { 
     return base.CreateControllerFactory(); 
    } 

    protected override Ninject.IKernel CreateKernel() 
    { 
     var kernel = new StandardKernel(); 
     kernel.Load("Thing.Web.Configuration.dll"); 
     return kernel; 
    } 

: 가끔 어떤 이유로 , Ninject에 (모듈은 Thing.Web.Configuration라는 별도의 DLL에있다) Asp.Net MVC와 통합하기 위해 PhotoC를 묶을 것입니다. ontroller 두 번. Ninject가 내가 원하는 PhotoController를 식별 할 수 없으므로 ActivationException이 발생합니다. 이로 인해 사이트의 축소판 및 기타 사용자 이미지에 대한 모든 요청이 실패하게됩니다. 여기

은 전체의에 PhotoController입니다 :

모든 컨트롤러가 정확히 같은 방식으로 작동하지만, 어떤 이유로 PhotoController 두 번 바운드 얻을 수
public class PhotoController : Controller 
{ 
    public PhotoController() 
    { 

    } 

    public ActionResult Index(string id) 
    { 
     var dir = Server.MapPath("~/" + ConfigurationManager.AppSettings["UserPhotos"]); 
     var path = Path.Combine(dir, id); 

     return base.File(path, "image/jpeg"); 
    } 
} 

. 심지어 그럴 때도 가끔씩 만 발생합니다 (솔루션을 다시 빌드하거나 앱 풀이 실행될 때 준비/제작 단계). 이런 일이 발생하면 아무 것도 변경하지 않고 다시 배포 할 때까지 계속 발생합니다.

그래서 ... 그게 뭐야?

+0

이 문제가 발생한 이유를 발견하지 못했습니다. 결국 Azure Blob 스토리지에서 컨텐트를 제공하면서 Generic Handler로 이미지에 액세스하는이 방법을 대체했습니다. – Dusda

+0

그러나 이론이 있습니다. 응용 프로그램의 모든 컨트롤러 작업 중에서이 작업이 가장 많이 이루어졌습니다. 이미지를 처리하므로 컨트롤러 작업은 페이지로드 당 15-30 번 발생합니다. 위에서 설명한 동작은 가능한 경쟁 조건을 의미합니다. – Dusda

답변

2

your answer to another similar question의 주석에서 알 수 있듯이 이것은 버전 2.2에서 수정 된 Ninject 2.0의 경쟁 조건 버그였습니다. Ninject에 대한 릴리스 노트를 찾을 수 없지만이 정확한 문제가 해결되었습니다.

+0

이것은 매우 도움이 될 것입니다.이 수정본이 언제 커밋되었는지 알고 싶습니까? –

+2

Google 용으로, 여기에 문제를 해결하는 커밋이 있습니다 : https://github.com/ninject/ninject/blob/a57a8879d23763f9fb2c272609a554f02350cd8d/src/Ninject/KernelBase.cs –

관련 문제