Themis, a bit dipper dive

I just committed some new code for Themis examples, which for now on, will be also an integration tests. The whole case is about values which are allowed for some roles.

Let’s take a case where there are two types of users: Admins and standard users, for the sake of briefness called Users. Let Admins are allowed to choice an offer type between Internal and External, and a standard user’s choice is narrowed to one value: Internal. How can a domain be modeled to handle it easily? First of all roles are needed:

public class AdminRoleDefinition : RoleDefinitionBase<Admin>
{
    public AdminRoleDefinition( )
    {
        ValueIsAllowed(OfferType.Internal);
        ValueIsAllowed(OfferType.External);
    }
}

public class UserRoleDefinition : RoleDefinitionBase<User>
{
    public UserRoleDefinition( )
    {
       ValueIsAllowed (OfferType.Internal);
    }
}

What’s the method ValueIsAllowed? It’s a simple, internal extension method, setting the possible value, using an markup demand.

public static class ServiceExtensions
{
    public static TValue[] GetAllowedValues<TValue>(this IDemandService @this, params object[] roles)
    {
        return @this.Evaluate<AllowedValueDemand<TValue>, TValue>(
                AllowedValueDemand<TValue>.Instance, roles);
    }
}

internal sealed class AllowedValueDemand<TValue> : IDemand<TValue>
{
    public static readonly AllowedValueDemand<TValue> Instance = new AllowedValueDemand<TValue>();
}

Having all this configured, now one can query a demand service for allowed values for a specific drop-down! It could be also done on the filtering basis with NHibernate, but it was an example how simply extensible Themis is.

Themis, take a break

Sometimes it’s good to take a break and give some ideas a while to regenerate in your head. After a few weeks of not touching Themis at all, I wrote a lot of documentation yesterday (and a few paragraphs today). I also recompiled it with the newest build of NHibernate, to allow you using with the newest fluent NHibernate. One more news is that Themis will be used in a production project. So far it brings profits but I’m ready to immerse into it if there any optimization/extension/refactorization will be needed.

Happy Themissing!