question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can be done differently the implementation of the DependencyScope?

See original GitHub issue

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 the dependency 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 the BeginScope method, I creat a childContainer and I call recursively the resolver:

var child = container.CreateChildContainer();
return new UnityResolver(child);

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 the BeginScope method, I create a dependencyScope object that take as parameter a LifeTimeScope. 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 the dependency scope. Here I write how I have done. In the dependencyResolver, inside the BeginScope method, I create a dependencyScope object that take as parameter the SAME instance of the container I am using. Then, inside the dependencyScope i do a begin 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?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
ghostcommented, Nov 22, 2017

I have an open PR where I am trying to get this exact idea merged. You can see the implementation we are going for here. The PR is also #351.

0reactions
ghostcommented, Mar 31, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Correct way to declare multiple scope for Maven ...
I would advise that this is the only scope which would be appropriate to declare in a dependencyManagement section. Your actual scope (runtime, ......
Read more >
Maven Dependency Scopes
Dependency scopes can help to limit the transitivity of the dependencies. They also modify the classpath for different build tasks.
Read more >
Introduction to the Dependency Mechanism - Apache Maven
Dependency scope is used to limit the transitivity of a dependency and to determine when a dependency is included in a classpath. There...
Read more >
Maven Dependency Scopes
Maven dependency scope attribute is used to specify the visibility of a dependency, relative to the different lifecycle phases (build, test, ...
Read more >
What are Maven dependency scopes and their related ...
This article explores Maven dependency scopes: what are they, what are they used for, and how do they impact security risks?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found