use custom IRepository interface in SharpModelBinder

26 views
Skip to first unread message

Paul Hinett

unread,
Jan 11, 2011, 1:05:12 PM1/11/11
to sharp-arc...@googlegroups.com

Hi,

 

I am setting up my project to use multi-tenancy from this fantastic article which popped up today:

http://www.yellowfeather.co.uk/2011/01/multi-tenancy-on-sharp-architecture/

 

However there is a problem which doesn’t seemed to be addressed which is the SharpModelBinder.

 

For the multi-tenant repositories to work they need to inherited from a custom class called MultiTenantRepository<>.

 

However the SharpModelBinder uses it’s own IRepositoryWithTypeId<>, is there an easy way to override this without changing the Sharp source code and re-compiling?

 

Thank you.

Paul

Chris Richards

unread,
Jan 12, 2011, 7:48:34 AM1/12/11
to S#arp Architecture
Hi Paul,

I've forked S#arp Architecture and made some minor changes to allow
different methods of getting the session factory key.

Basically I've created an interface ISessionFactoryKeyProvider to hide
the details of getting the session factory key. The default
implementation I've added, DefaultSessionFactoryKeyProvider, uses the
existing SessionFactoryAttribute so the only change required to
existing application is to register DefaultSessionFactoryKeyProvider
in the container. To use a different method it is just a case of
providing and registering your own implementation of
ISessionFactoryKeyProvider.

I've made a pull request (https://github.com/sharparchitecture/Sharp-
Architecture/pull/1) so hopefully this will make it into the mainline
at some point in the future.

These changes simplify adding multi-tenancy to an app. The
MultiTenenatRepository from my post is no longer required and the
binder should now work. The custom TransactionAttribute is also no
longer required. The sample project https://github.com/yellowfeather/SharpArchitecture-MultiTenant
has been updated to use my forked version of S#arp Architecture.

Blog post coming later in the week.

Cheers,
Chris

On Jan 11, 6:05 pm, "Paul Hinett" <p...@ukcreativedesigns.com> wrote:
> Hi,
>
> I am setting up my project to use multi-tenancy from this fantastic article
> which popped up today:
>
> http://www.yellowfeather.co.uk/2011/01/multi-tenancy-on-sharp-archite...

Paul

unread,
Jan 12, 2011, 5:57:22 PM1/12/11
to S#arp Architecture
Thank you so much, I attempted this myself last night but went the
wrong way about it. These seems much more elegant!

1 question though, I have created a custom repository called
ITenantRepository with a function to return all tenants and eager load
some config settings for each config.

But the tenantRepository is trying to use a session factory for one of
my tenants instead of the default...how can i override the factory key
for this repository...I may be overlooking something simple here.

Thank you for your efforts!

Paul

On Jan 12, 12:48 pm, Chris Richards
<chris.richa...@yellowfeather.co.uk> wrote:
> Hi Paul,
>
> I've forked S#arp Architecture and made some minor changes to allow
> different methods of getting the session factory key.
>
> Basically I've created an interface ISessionFactoryKeyProvider to hide
> the details of getting the session factory key. The default
> implementation I've added, DefaultSessionFactoryKeyProvider, uses the
> existing SessionFactoryAttribute so the only change required to
> existing application is to register DefaultSessionFactoryKeyProvider
> in the container. To use a different method it is just a case of
> providing and registering your own implementation of
> ISessionFactoryKeyProvider.
>
> I've made a pull request (https://github.com/sharparchitecture/Sharp-
> Architecture/pull/1) so hopefully this will make it into the mainline
> at some point in the future.
>
> These changes simplify adding multi-tenancy to an app. The
> MultiTenenatRepository from my post is no longer required and the
> binder should now work. The custom TransactionAttribute is also no
> longer required. The sample projecthttps://github.com/yellowfeather/SharpArchitecture-MultiTenant

Chris Richards

unread,
Jan 12, 2011, 6:29:47 PM1/12/11
to S#arp Architecture
That is something I hadn't considered, if you're trying to access the
master database whilst responding to a request on a subdomain it will
provide the session factory key for the tenant. Will have a think how
best to solve it and post an update.

As a workaround, you can override the Session get method to use
NHibernateSession.DefaultFactoryKey.

Chris

Chris Richards

unread,
Jan 12, 2011, 7:04:20 PM1/12/11
to S#arp Architecture
I think the best way to solve this is to reinstate the
IMultiTenantRepository marker interface, add this to the appropriate
repositories and update MultiTenantSessionFactoryKeyProvider so that
it checks for the implementation of this interface. If it is
implemented then attempt to get the factory key from the tenant
context otherwise just return NHibernateSession.DefaultFactoryKey.

I'll test this tomorrow and update my sample project.

Chris

On Jan 12, 11:29 pm, Chris Richards

Seif Attar

unread,
Jan 13, 2011, 3:58:15 AM1/13/11
to sharp-arc...@googlegroups.com
Thanks for sharing this Chris, i think this would make a good addition to contrib, what do you guys think?




--
You received this message because you are subscribed to the Google Groups "S#arp Architecture" group.
To post to this group, send email to sharp-arc...@googlegroups.com.
To unsubscribe from this group, send email to sharp-architect...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sharp-architecture?hl=en.

Howard van Rooijen

unread,
Jan 13, 2011, 4:46:52 AM1/13/11
to sharp-arc...@googlegroups.com
We could include some of the core interfaces into the main SA project - if this makes it easier for the rest of the MT code to be a "bolt on feature" rather than a source code integration task?

Chris Richards

unread,
Jan 13, 2011, 8:52:42 AM1/13/11
to S#arp Architecture
I've just pushed some updates to my sample app so that the correct
session factory key is used for standard and multi tenant repositories
(by using reflection and the IMultiTenantEntity and
IMultiTenantRepository marker interfaces).

Also, I've reorganised the code slightly which would make it easier to
add to contrib if desired (just add everything in the
SharpArchitecture.MultiTenant.Framework project). The changes to the
main SA in my pull request (https://github.com/sharparchitecture/Sharp-
Architecture/pull/1) would be required though.

On Jan 13, 9:46 am, Howard van Rooijen <howard.vanrooi...@gmail.com>
wrote:
> We could include some of the core interfaces into the main SA project - if
> this makes it easier for the rest of the MT code to be a "bolt on feature"
> rather than a source code integration task?
>
>
>
>
>
>
>
> On Thu, Jan 13, 2011 at 8:58 AM, Seif Attar <i...@seifattar.net> wrote:
> > Thanks for sharing this Chris, i think this would make a good addition to
> > contrib, what do you guys think?
>
> > ------------------------------
> > On 13 Jan 2011 00:04, Chris Richards <chris.richa...@yellowfeather.co.uk>
> > sharp-architect...@googlegroups.com<sharp-architecture%2Bunsubs cr...@googlegroups.com>.
>
> > For more options, visit this group at
> >http://groups.google.com/group/sharp-architecture?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "S#arp Architecture" group.
> > To post to this group, send email to sharp-arc...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > sharp-architect...@googlegroups.com<sharp-architecture%2Bunsubs cr...@googlegroups.com>

Alec Whittington

unread,
Jan 13, 2011, 11:53:34 AM1/13/11
to sharp-arc...@googlegroups.com
I think this would be a most welcome addition to the S# code base. I agree with Howard that some of it can go into the core bits.

Great job Chris, thanks for sharing.
To unsubscribe from this group, send email to sharp-architect...@googlegroups.com.

Chris Richards

unread,
Jan 14, 2011, 7:08:52 AM1/14/11
to S#arp Architecture
What's the best way of proceeding?

My existing pull request is against SA 1.9, do you want me to merge my
changes into 2.0 and send another pull request?


On Jan 13, 4:53 pm, Alec Whittington <alec.whitting...@gmail.com>
wrote:
> I think this would be a most welcome addition to the S# code base. I agree
> with Howard that some of it can go into the core bits.
>
> Great job Chris, thanks for sharing.
>
> Cheers,
> Alec Whittington
> twitter:http://twitter.com/alecwhittington
> <http://twitter.com/alecwhittington>blog:http://blog.sharparchitecture.net
> Become a fan of S#arp Architecture on
> Facebook<http://www.facebook.com/pages/Sarp-Architecture/117591724971997>
> > > > sharp-architect...@googlegroups.com<sharp-architecture%2Bunsubs cr...@googlegroups.com><sharp-architecture%2Bunsubs
> > cr...@googlegroups.com>.
>
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/sharp-architecture?hl=en.
>
> > > >  --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "S#arp Architecture" group.
> > > > To post to this group, send email to
> > sharp-arc...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > sharp-architect...@googlegroups.com<sharp-architecture%2Bunsubs cr...@googlegroups.com><sharp-architecture%2Bunsubs

Alec Whittington

unread,
Jan 14, 2011, 10:08:06 AM1/14/11
to sharp-arc...@googlegroups.com
Chris,
     the team is meeting on Sunday, we will discuss then the best way for us to adapt this. I think our current plan is to take part of it into S# and the other part into contrib. We'll let you know shortly.

Cheers,
Alec Whittington
To unsubscribe from this group, send email to sharp-architect...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages