Enable Nhibernate filters by default

Is there a way to make sure filter ( <filter-def>) is enabled by default, and not to be called session.EnableFilter("filter_name")every time?

+3
source share
1 answer

I understand that this cannot exactly solve your problem, but it can be done if you connect your objects through an IOC container or if you have one point at which you are creating a session.

How I handled this when activating ISession. I switched the filter by default (using Autofac):

        builder.RegisterAdapter<ISessionFactory, ISession>(factory => factory.OpenSession())
            .InstancePerHttpRequest()
            .OnActivated(activatedArgs =>
                         {
                             var session = activatedArgs.Instance;
                             session.EnableFilter(MyCustomFilter.Name);
                             session.BeginTransaction();
                         });
+4
source

Source: https://habr.com/ru/post/1704266/


All Articles