Auditing - using dependency injection and CreateAuditor

Posts   
 
    
nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 22-Mar-2012 22:05:53   

I'm looking through the documentation on Auditing and Dependency injection and theres a part that i don't quite understand.

How can i override the CreateAuditor method of the generated code to return an Auditor that is not in the genereted code's assembly?

Here's the basic idea:

MyApplicationABC - contains a config dependencyInjectionInfo section which points to MyBusinessLogicABCAssembly.

MyBusinessLogicABCAssembly - contains MyAuditorABCClass which inherits from AuditorBase

MyGeneratedCode.DAL -- here SomeEntity class would have an overridden CreateAuditor method which would return MyBusinessLogic.MyAuditorClass -- but how, since the generated code assembly has not reference to MyBusinessABCLogicAssembly?

Also, if i understand this i should be able to create another app MyApplicationXYZ and then create a different MyBusinessLogicXYZ with MyAuditorXYZ as well. But then how to i ensure that the generated code uses MyAuditorXYZ?

In Short, is it possible to ensure that the correct auditor is used by the generated DAL only with dependency injection? or do i need to always attach the proper auditor in the code using SomeEntity.AuditorToUse = MyAuditorXYZ?

nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 22-Mar-2012 22:42:24   

so long story short: how can i determine which auditor to use at runtime, while still ensuring that an auditor is used?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Mar-2012 07:09:33   

You don't need to override CreateAuditor if you already are using DependencyInjection. DI is responsible of loading your auditor (in whatever assembly you write this), instantiate it, and inject it into the target injectable classes (usually in your DBGeneric assembly).

How do you know what Auditor is instantiated? Well that depends what auditor assembly is reachable from your solution. You can put the appropriate assembly in the solution output, or reference it in your GUI/Console/etc project, so it will always be copied to the output, that way DI always can found it.

What entities are injected by that Auditor? That depends on how you configure the auditor.

For more info read Setting up and using Dependency Injection, and come back here if you need further assistance on this.

David Elizondo | LLBLGen Support Team