.NET – Can I use IOC containers to create a dependency that requires runtime values?

I am new to IoC, so I want to know if it is the right tool for the job I want to do.

I am writing a multi-tenant application Program, there are several places where we may want to use different interface implementations according to the organization to which the currently logged-in user belongs.

For example, when a user of an organization creates a work order, we need to ask the user’s supervisor Send an email. But for all other organizations, you don’t need to send that email. Classic strategy mode stuff.

My question is, can I instruct the IoC container to view a certain runtime value in some way (In this case, the OrganizationId of the logged-in user) to determine which implementation of IWorkOrderProcessor should be injected into the constructor of the object that needs it?

I am currently using Windsor, but examples of using other containers would be good.

Windsor has an extension point that is very suitable for multi-tenant applications: IHandlerSelector.

> http://ayende.com/Blog/archive/2008/10/05/windsor-ihandlerselector .aspx
> http://mikehadlow.blogspot.com/2008/11/multi-tenancy-part-2-components-and.html

This allows you to code your application as not Multi-tenant. Multi-tenant logic is moved out of business logic.

I am new to IoC, so I want to know if it is the right tool for the job I want to do.

I am writing a multi-tenant application. There are several places where we may want to use different interface implementations according to the organization of the currently logged-in user.

For example, when When a user of an organization creates a work order, they need to send an email to the user’s supervisor. But for all other organizations, you don’t need to send that email. Classic strategy mode stuff.

My question is, Can I somehow instruct the IoC container to look at a certain runtime value (in this case, the OrganizationId of the logged-in user) to determine which implementation of IWorkOrderProcessor to inject into the constructor of the object that needs it?

I am currently using Windsor, but examples of using other containers would be good.

Windsor has an extension point, which is very suitable for many Tenant application: IHandlerSelector.

> http://ayende.com/Blog/archive/2008/10/05/windsor-ihandlerselector.aspx
> http://mikehadlow. blogspot.com/2008/11/multi-tenancy-part-2-components-and.html

This allows you to code your application as not multi-tenant. Multi-tenancy logic is moved out of business logic.< /p>

Leave a Comment

Your email address will not be published.