Resolving User Id (who) in custom Auditor in .Net 5

Posts   
 
    
andreash
User
Posts: 5
Joined: 03-Feb-2021
# Posted on: 18-Apr-2021 19:21:41   

We are using LLBLGen Pro v5.7 and .Net 5 and we built a custom Auditor in a separate class and project. We are following the official examples: https://github.com/SolutionsDesign/LLBLGenProExamples_5.x/tree/master/Example_Auditing https://www.llblgen.com/Documentation/5.8/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/gencode_auditing.htm

The first example retrieves the User Id from HttpContext which is not available in .Net Core. Instead, we need to inject IHttpContextAccessor which we failed to do with LLBLGen's custom Dependency Injection framework.

Any ideas how we can achieve this? Also, is it possible to integrate LLBLGen's DI with .Net build-in DI?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 19-Apr-2021 09:38:18   

The example uses a static method to obtain the user id from the session, which is indeed a Webforms concept and isn't available in asp.net core. There might be ways to obtain values from an ISession object through static methods but indeed it won't be easy.

In v5.8 we implemented support for 3rd party DI frameworks, like the one in asp.net core. See: https://www.llblgen.com/Documentation/5.8/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/gencode_usingdi.htm#using-another-dependency-injection-framework for how to use that, which should be straight forward.

Frans Bouma | Lead developer LLBLGen Pro
andreash
User
Posts: 5
Joined: 03-Feb-2021
# Posted on: 19-Apr-2021 14:23:17   

Thanks Frans! We will check the newer version.