Ormlite createdBy & lastUpdatedBy

Because when you have 30 entities, several relations, several related lists, you want to ensure by the infrastructure that these fields are managed correctly.
Its not smart save audit for each implementation differently…

Do you have any plan to make security context accesible in the entire app?

Your App is exactly who should be populating your Audit fields since only you’ll know which fields you want populated with what info. Not sure why you’d each populate them differently, have them all call a common method as done in my example above.

There can never be a non static filter, you’re calling a library API which isn’t physically able to access any external dependencies unknown to it like your App or web frameworks it’s called from, it also can’t access object instances it wasn’t called with (you’re requesting to do both), so if you’re not passing in a request context then how can it be possible for an ORM to be able to provide a filter that’s able to access it other than anything apart from a static context? Like how exactly is it supposed to be able to access a non static instance it wasn’t called with to be able to inject it in a filter?

As far as I underststand, The fact that the filter is static prevent us from accessing anything in a certain context.

Your App is exactly who should be populating your Audit fields since only you’ll know which fields you want populated with what info

I have:

public class BaseEntity{
      //Id...
        [Reference]
        public AppUserAuth? CreatedBy { get; set; }
        [References(typeof(AppUserAuth))]
        public int? CreatedById { get; set; }


        [Reference]
        public AppUserAuth? LastUpdatedBy { get; set; }
        [References(typeof(AppUserAuth))]
        public int? LastUpdatedById { get; set; }
       ....
}

//Everyone is inheriting from `BaseEntity`

public class CustomerEntity : BaseEntity{
     //references
     public List<CarEntity> Cars{ get; set; } //BaseEntity
     public List<DocEntity> Dogs{ get; set; } //BaseEntity
     public  LawyerEntity  Laywer{ get; set; } //BaseEntity
}

I have several services saving in all kind of ways the CustomerEntity .

Db.Save(customerFromAClient, true);// can have indide new Cars, new Docds…

customerEntityFromDb.Cars.Add(carFromAClient);
Db.Cars.Save(customerEntityFromDb, true);

var car = new CarEntity{CustomerId = 1};
Db.Save(car);

I need to handle that in each and every case, there are a lot more cases. I think this shouldb be handled from one place. line in hibernate for example

if(entity is BaseEntity){
   if(newly created){
       entity.CreatedById  = securityContext.User.Id;
   }else{
       entity.LastUpdatedBy  = securityContext.User.Id;
  }
}

In servicestack, The only way in a large app to handle that once and for all cases is via relection some how…

And how exactly can NHinernate get its security context in .NET Core which disables static access to its request context by default? Given it’s not possible, it has to enable it, so if that’s what you want to do then you’ll need to register the HttpContextAccessor, i.e:

public void ConfigureServices(IServiceCollection services)
{
     services.AddHttpContextAccessor();
}

Then you can access an IRequest Context from HttpContext.TryGetCurrentRequest() in your static filters invoked from a HTTP Worker thread, i.e. it’s not possible from a background thread.

This has performence problems, lets hope it will not be depricated…
Thanks

The additional performance overhead is why it was disabled by default, but they’re not going to remove the option for being able to add it.