2014-10-14 6 views
1

Я использую Autofac с WCF. Мой сервис (ExportWebService) должен зависеть от зависимостей (ExportService). Установка Я, ApplicationStart сделать это:Autofac - Область экземпляра WCF

builder.Register(c => new ExportWebService(c.Resolve<ExportService>())); 

Но когда я делаю это я получаю ошибку:

No scope with a Tag matching 'httpRequest' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being reqested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.

Я также попытался:

builder.RegisterType<ExportWebService>().InstancePerHttpRequest(); 

В моей службы у меня есть :

public ExportService ExportService 
{ 
    get; 
    set; 
} 

public ExportWebService(ExportService exportService) 
{ 
    ExportService = exportService; 
} 

Любая идея, что есть w Ронг здесь?

ответ

0

Autofac WCF поддержка не имеет InstancePerRequest семантика. There is a detailed FAQ on troubleshooting per-request dependencies, что может быть интересно, но короткая версия здесь, вероятно, должна была бы изменить регистрацию вашего ExportService на SingleInstance или InstancePerDependency.

+2

Я фактически изменил его на InstancePerLifetimeScope() на основе следующего: https://groups.google.com/forum/#!msg/autofac/vPrvd0RtOtM/MKuGueLmMpEJ, и теперь он работает. – user472292

Смежные вопросы