Profile picture Schedule a Meeting
c a n d l a n d . n e t

IoC smell: Having IContainerAccessor as a dependency.

Dusty Candland | |

Looking back, it should have been an obvious thing to not do, but it wasn’t. I wanted to get access to the container and so I made IContainerAccessor a dependency for my class. The I added that to the container. The Main problem was that the IContainerAccessor interface was implemented on the class that also created the container. So, after startup I had two containers, one I created for the application and one that container created when the IContainerAccessor was created.

Okay, there are other ways to implement the IContainerAccessor, but is that what I really needed? No, I really needed a way to create a specific kind of component. Maybe like a factory of some sort. Oh, yea the factory pattern is already sitting around waiting to be used. And it was a good solution here.

That makes me think, for most cases where you want the container directly, there is a better solution waiting to be used.

Webmentions

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: