2016-08-13 1 views
1

나는SharpRepository를 AutoFac 및 Entiry Framework와 함께 사용하려면 어떻게 설정해야합니까?

SharpRepository.EfRepository 
SharpRepository.Ioc.Autofac 
SharpRepository.Repository 
설치하고 Autofac 문서의 지시에 따라 나는 설정 Autofac이 코드를 추가 한 :

void SetupAutofac() 
    { 
     var builder = new ContainerBuilder(); 

     // Get your HttpConfiguration. 
     HttpConfiguration config = GlobalConfiguration.Configuration; 

     // Register your Web API controllers. 
     builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); 

     // OPTIONAL: Register the Autofac filter provider. 
     builder.RegisterWebApiFilterProvider(config); 

     // Set the dependency resolver to be Autofac. 
     IContainer container = builder.Build(); 
     config.DependencyResolver = new AutofacWebApiDependencyResolver(container); 
    } 

하지만 SharpRepository가 Autofac 나에게 ​​도움이되지 않습니다 가이드를 시작하기 - -> EF -> SharpRepo는 StructureMap을 지향하므로 접착제를 사용합니다. 제발 조언!

(I 가능한 경우의 Web.config에 물건을 넣어하지 않도록하고 싶습니다)

답변

1

당신은 당신이하지 않은 경우 SharpRpository.Ioc.Autofac NuGet 패키지를 설치해야합니다.

그럼 당신은 어떻게 IRepository을 처리하는 Autofac에게하기 위해

builder.RegisterSharpRepository() 

를 호출합니다. 이 EF를 필요로 할 때

그런 다음 당신이 그것을 어떻게해야

RepositoryDependencyResolver.SetDependencyResolver(new AutofacDependencyResolver(container)); 

를 호출해야합니다 Autofac를 사용하는 SharpRpository 말할 수 있습니다.

관련 문제