hmemcpy / AgentMulder

** THIS PLUGIN IS NO LONGER MAINTAINED. PLEASE FOLLOW ERNICOMMUNITY FOR UPDATES **
https://github.com/ERNICommunity/AgentMulder
MIT License
151 stars 33 forks source link

Refactor new statement to container user #16

Open nesteruk opened 12 years ago

nesteruk commented 12 years ago

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 12 years ago

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 :)

nesteruk commented 12 years ago

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 12 years ago

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