This repository has been archived by the owner. It is now read-only.

Refactor new statement to container user #16

nesteruk opened this Issue Jun 19, 2012 · 3 comments


None yet
2 participants

I think the whole point of IoC support is to do this and, furthermore, to do this en masse. What I mean is that instead of new Foo() you could give options to refactor it to either container.Resolve<Foo>() or -- and this is tricky -- to have Foo injected into the containing class.

Having a refactoring, you could easily do a Code Cleanup module that could perform this change on the whole solution. The net result would be epic: anyone who's just starting with IoC can refactor their whole codebase to use IoC in just one click.

That's my dream IoC feature, anyway.


hmemcpy commented Jun 19, 2012

I really like this idea. In fact, I want to believe that Agent Mulder could become the "missing link" in the tooling to work with IoC better - analysis for component registration, quickfixes for registration issues and indeed - the "refactor to container", as you propose. I'll put this in the milestone Mirabile Futurum, because it is where it currently belongs :)

BTW, I just remembered something: the container itself is injectable. This could cause certain complications because different components could inject, say, IUnityContainer and then add extra registrations on top or, for example, explicitly Resolve() on it.

This isn't a recommended use pattern, however, so perhaps some extra refactorings could be available for this too.


hmemcpy commented Jun 19, 2012

I wonder if somehow ReSharper's value analysis (origin, destination) can be useful for this. I never used this feature myself...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.