2
votes

The project am working implements IOC/DI using castle windsor. There are many modules in project. There is a module called ProcessEngine that send the Invoices to my module for Automatic Process which involves 7 steps.

Up to now ProcessEngine module use to send Invoices one by one as in a queue and my module worked perfectly. But now ProcessEngine send many invoices that are ready by spanning them in different threads each invoice having there own thread so the problem arises.

The problem I see is that the instances are created by using Castle Windsor and it returns the same object everytime. That means all threads are having same instance and it creates the chaos. Then I created instances of major classes that have some private properties by using new keyword and it worked fine.

Is there any way I can restrict Castle Windsor container to return new instance everytime for some of the classes of my module? It is Architecture guideline of the project that object must be instantiated using Castle Windsor not using new keyword. Is there any solution for this?

Any help will be highly appericiated. I dont have much knowledge of Castle Windsor but I observed It is kind of Singleton Pattern as it returns same object everytime using Castle Windsor.

1
You should consider using paragraphs, not using them makes your question hard to read.svick

1 Answers

3
votes

You need to check lifestyles.

Default behaviour is singleton, which means it will indeed return the same instance when you ask for resolve.

You can use PerThread or Transient lifestyle.