use external DI / IOC framework

Posts   
 
    
mdissel
User
Posts: 92
Joined: 16-Sep-2003
# Posted on: 12-Dec-2013 09:50:54   

Hello

Is it possible to use an external DI / IOC framework like structuremap / simple injector to inject the Validator / Authorize classes into the entities?

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 12-Dec-2013 10:03:38   

Yes, with one remark: to be successful with this, the entity factories have to call into the DI framework you're using, so you have to adjust the factories. This can be done with a template change. I have no idea how these frameworks work, so I don't know what you have to change, the thing I do know is that every instantiation of an entity has to go through their factories, so our factories have to do that (they now simply call new)

Out of interest, why use an external framework when a DI framework is built-in?

Frans Bouma | Lead developer LLBLGen Pro
mdissel
User
Posts: 92
Joined: 16-Sep-2003
# Posted on: 12-Dec-2013 15:20:04   

of course .. change the templates.. Thanks!

Why? because all our customers wants different validations and different authorizations.. We have default behaviour that can be overriden for each customer.

We don't want to change the config files to change the behaviour but just copy a DLL that will contain the customisations..

Why not add a simple interface that's callled to resolve the classes? Out of the box the default implementation is used, but you can create your own implementation (and use your own DI framework).

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 13-Dec-2013 10:17:34   

mdissel wrote:

of course .. change the templates.. Thanks!

It's not only the templates, but also your code: you can't do this anymore: var newCustomer = new CustomerEntity();

because an external DI framework won't be called that way. You have to use the factory of the DI framework you're using for this.

There's another way, I didn't think of that. see below.

Why? because all our customers wants different validations and different authorizations.. We have default behaviour that can be overriden for each customer.

We don't want to change the config files to change the behaviour but just copy a DLL that will contain the customisations..

Our DI system can do that. It has an automated discovery system: just specify that you want autodiscovery and it finds the di assemblies. If you use a website, you need to specify the assembly, but you could keep that the same name.

You can also use a scope, setup in the application startup.

Why not add a simple interface that's callled to resolve the classes? Out of the box the default implementation is used, but you can create your own implementation (and use your own DI framework).

You can do that, override PerformDependencyInjection in a partial class of CommonEntityBase. In there call your DI framework of choice (or your own code). By default it calls our own engine.

Frans Bouma | Lead developer LLBLGen Pro