Following my previous post some issues were pointed out with the implementation, the main one being that the correct repository implementation was not resolved from an IRepository<T> interface (see the Google Group discussion for more details).
As mentioned in the discussion I have made some minor modifications to S#arp Architecture to solve this problem and better support multi-tenancy. You can see the changes in the pull request, but it looks like they are now included in the latest release.
The changes are very minor, and centre around the introduction of an interface, ISessionFactoryKeyProvider, so that it is possible to get the session factory key without having to use an attribute:
I’ve created a default implementation of this interface that just delegates getting the key from the existing SessionFactoryAttribute.
I’ve also added a helper class SessionFactoryKeyHelper:
Now whenever S#arp Architecture requires a session factory key we can use the helper class, rather than using SessionFactoryAttribute e.g. in the Repository implementation the code is changed from:
to:
Note: this change to the Repository implementation means that the MultiTenantRepository class from my previous post is no longer required.
Similar changes are also made to TransactionAttribute and EntityDuplicateChecker.
If you do not need multi-tenancy, or are happy to use the existing TransactionAttribute to specify the session factory key, then you just need to register the DefaultSessionFactoryKeyProvider implementation in the container:
But if you want to provide the session factory key by any other means, it is just a case of implementing and registering your implementation of ISessionFactoryKeyProvider.
This makes use of a couple of marker interfaces IMultiTenantEntity and IMultiTenantRepository to decide whether we need to get the tenant, or the default, session factory key. Actually getting the tenant session factory key is accomplished by the implementation of ITenantContext.
I’ve update my sample application on GitHub with these changes and to run against S#arp Architecture v1.95.