Fabio, thanks for the hint.
I've solved it using filters (defined programatically) and an interceptor.
Just in case that someone is interested I've described my solution here:
http://blog.schuager.com/2009/02/contextual-data-using-nhibernate.html

Regards.

On Wed, Feb 11, 2009 at 10:35 AM, Fabio Maulo <[email protected]> wrote:

> NH filtering is a great feature.Fliters are applied as expected in a lot
> of query but... not in all (we have one open bug about it).
> Before implement some strange thing try "Filters".
>
>
> 2009/2/11 Germán Schuager <[email protected]>
>
> Hi,
>> I have the following requirement:
>>
>> I need to introduce the concept of "Mode of execution" in my application:
>> * Certain classes provide a Mode property.
>> * The instances of this classes will be only visible when the current
>> application Mode of execution is equal to its Mode property value.
>> * New instances need to be asigned the current Mode of execution before
>> persisting them.
>>
>> Currently my services call catRepository.GetAll() and this get traduced to
>> hql "from Cat". I see 2 options here:
>> * implementing the requirement in the application layer means that the
>> services need to be changed to use catRepository.GetAllWithMode(mode)
>> explicitly (lots of places to modify)
>> * implementing the requirement in the domain/data layer in a generic way
>> means that the GetAll() call would be traduce to hql "from Cat c where
>> c.Mode = currentMode"
>>
>> I've been thinking in the following solution:
>>
>> public interface IModeAware
>> {
>>     Mode Mode { get; set; }
>> }
>>
>> Using interceptors or event listeners I would asign the current Mode of
>> execution to every implementor of IModeAware before persisting it.
>> My problem is to query those classes... I've thought about using filters
>> but I've found 2 minor issues:
>> 1. I haven't found a way to enable/disable a filter at SessionFactory
>> scope, it needs to be done for each Session that is created.
>> 2. I need to define the same filter in the mapping of each class
>> implementing IModoAware (is there any way to specify polymorphic filters?)
>>
>>
>> To sum up, as I've never used these features before I'm looking for some
>> advice about whether this approach will get me into trouble (that I'm not
>> seeing) or if I should be ok.
>>
>>
>>
>>
>
>
> --
> Fabio Maulo
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to