I use the windsor in the castle for my favorite project I'm working on. I'm starting to notice that I need to call the IoC container in different places in my code to create new objects. This container dependency simplifies my code.
There are two solutions that I used to solve this problem.
I tried to create abstract factories as wrappers around a container that I could embed in the parts of my application that should create objects. This works, but has some drawbacks, because the lock makes it difficult to add its own container to dependency. So I have to do it manually, this view defeats the whole purpose of the IoC container.
I used the main class applicationcontroller to migrate the IoC container and work as a central factory / repository. It was pretty successful, but this class gets too big and acts like a central god object, almost all other objects refer to it.
Both solutions do their job, but both have their drawbacks. Therefore, I am wondering if other people have the same problem and have found better solutions.
edit The problem is not in object A, which depends on object B. Here I usually use only constructor injection, and everything works. Sometimes I have objects of type A that need to create a variable number of other objects of type B over their lifetime. I am not sure how to do this.
@Blair Conrad: Maintenance problems are not serious so far. I had several classes depending on the container container calling the container. Resolve <>. And I do not want my code to depend on what I consider to be infrastructure. I am still trying, so I noticed that I had to change a lot of code when switching from ninject to lock for this project.
@flowers: Hmm. I like the decision of your fists. It combines what works with both solutions that I tried. I think I was still thinking too much about objects and not enough in interfaces / responsibilities. I tried whole plants, but I would like them to use the container backstage to create objects, and I did not find out how I can make a container a container in a clean way.
oop dependency-injection inversion-of-control castle-windsor
Mendelt Sep 20 '08 at 22:48 2008-09-20 22:48
source share