zcz527 / autofac

Automatically exported from code.google.com/p/autofac
Other
0 stars 0 forks source link

No scope AutofacWeb.... problem on manual resolving #375

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Try to use manual resolver
2. GlobalConfiguration.Configuration.DependencyResolver.GetService

What is the expected output? What do you see instead?
My InstancePerApiRequest instace will be created when add the interface on my 
webApiController but not when try to load it manuallay inside my webApi

What version of Autofac are you using? On what version of .NET/Silverlight?

Latest rc, web api 4 RC

Please provide any additional information below.
Get this error:

"No scope with a Tag matching 'AutofacWebRequest' 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."

Seams like there is a problem using manual resolving? 
When debug I got all my instansex in the service list on the Configuration...

Original issue reported on code.google.com by johan.no...@squeed.com on 20 Jun 2012 at 7:22

GoogleCodeExporter commented 8 years ago
In Web API the global dependency resolver is used to access global instances. 
Per-request services come from a dependency scope that Web API creates to 
handle the request. I'm not sure that there is any way to access the current 
dependency scope - this might be a question for the Web API folks.

Autofac has features that can be used to avoid having to use the Service 
Locator pattern like this - feel free to shoot an email describing your 
scenario to the mailing list and we'll see if we can help out.

Original comment by nicholas...@gmail.com on 21 Jun 2012 at 4:14