내가 표준 StructureMap 기반 ControllerFactory 설정이 HttpContext를 당 한 번 이상 인스턴스화하는 것을, 나는, 각 유형 IRepository
의 종속성이 다양한 종속성이 그래서 같은 컨트롤러가 있습니다플러그인
// "web" assembly
public StructureMapRegistry : Registry
{
public StructureMapRegistry()
{
Scan(scanner =>
{
scanner.AssemblyContainingType<WidgetController>();
scanner.AssemblyContainingType<Repository>();
scanner.WithDefaultConventions();
});
For<IRepository>().HybridHttpOrThreadLocalScoped().Use<Repository>();
}
}
public WidgetController(IService1 service1, IService2 service2, Service3 service3)
{
// etc, etc
}
// "data" assembly
public Service1 : IService1
{
public Service1(IRepository repository)
{
// etc, etc
}
}
public Service2 : IService2
{
public Service2(IRepository repository)
{
// etc, etc
}
}
public Service3
{
public Service3(IRepository repository)
{
// etc, etc
}
}
을
GetHashCode()
등을 사용하면 WidgetController
이 모두 동일한 인스턴스를 사용할 것으로 예상 될 때 각각의 서비스에서 인스턴스화되는 새로운 Repository
이있는 것으로 보입니다.
내가 무엇을 오해합니까? HybridHttpOrThreadLocalScoped()
은 무엇입니까? 왜냐하면 저는 때때로 위의 코드에서 Service3
(IRepository는 항상 사용되지만 결코 리파지토리의 구체적인 클래스)에서와 같이 의존성 대신 인터페이스 대신 구체적인 클래스를 전달하기 때문입니까? 나는 이걸 완전히 잘못하고 있니?
참고 : 나는 StructureMap 2.6.1을 사용하고 있습니다.