-
Notifications
You must be signed in to change notification settings - Fork 459
Can be done differently the implementation of the DependencyScope? #366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you for answer.. I look at it |
I have some further questions. Just trying to understand the question you ask when you say:
Can you explain what lifestyles they were registered with? Singleton, Scoped or Transient? It will help me understand what your current setup is. Do you also mind posting a code sample for clarity? @jonorossi and I have been talking about "Instances Per Matching Lifetime" scope from Autofac for this PR but I just need to be sure that is what you mean. I feel engaging the resolution mechanism from a scope for a container mutates the intent of the lifestyle for original registration of what that component was originally intended for when it comes to implementing IDisposable. It creates permutations around whether a singleton is in fact a singleton or whether it is a scoped singleton. I am sure you can appreciate these are fundamentally different. Also in Windsor today, singletons are disposed when the container get's disposed. Are we saying that singletons get disposed when a scope is started, a singleton gets resolved and the scope get's disposed? If so, this changes the meaning of a singelton. I feel this is fundamentally wrong. Based on the original writings from "Gang of four" this should be a process wide lifestyle. The implications of indicating intent via registation and then having their behaviour mutated via scopes are ugly. The AspNet team did this with their dependency injection abstractions for dotnet core. I cannot say I am happy with the result(I am not the only one), it also earned Windsor the title of a "non conforming container" which I thought was peculiar. Look forward to your response, and code sample. Let's see how we can make this work. |
@scoppini - Have you had a chance to look at this? We have not released yet and would love to hear some feedback. |
Also wrote some docs for this here: https://github.com/castleproject/Windsor/blob/master/docs/aspnetwebapi-facility.md |
Hi everyone,
I am writing a new web api application using Windsor. I've always used Microsoft Unity and Autofac. Now I want to try Windsor.
But something is not clear using Windsor. I have seen how everyone, all people, write the
dependency resolver
and thedependency scope
.Honestly, I do not like that way... It seems muddler to me... but perhaps because I have not understood something..
I try to explain what I mean talking about my experience with Unity and Autofac. The question I want to answer is: How do I start a new scope in "every" DI framework?
Microsoft Unity
In the
dependencyResolver
, inside theBeginScope
method, I creat a childContainer and I call recursively the resolver:In this way, every service resolved in the child container will have the scope of the child container. The scopes of the child containers are the classic scopes: Singleton, PerWebRequest, ....
Autofac
In the
dependencyResolver
, inside theBeginScope
method, I create adependencyScope
object that take as parameter aLifeTimeScope
. Then, I resolve everyting in the lifeTimeScope:new AutoFacDependencyScope(_container.BeginLifetimeScope());
Here, how resolve the service(s) in the
AutoFacDependencyScope
:_lifetimeScope.TryResolve(serviceType, out instance);
As you can see, the services are resolved using the lifeTimeScope, not the container.
Windsor
Surely you know better than me how to implement the
dependency resolver
and thedependency scope
. Here I write how I have done.In the
dependencyResolver
, inside theBeginScope
method, I create adependencyScope
object that take as parameter the SAME instance of thecontainer
I am using. Then, inside thedependencyScope
i do abegin scope
and I resolve the services in the container I passed from outside.It looks like nothing changed... I am resolving everything inside the main container just with the difference that before I have called a begin scope... perhaps that is enough to create everything with a scope... but it is not explicit... I am just supponsing...
Is it correct this way?
The text was updated successfully, but these errors were encountered: