2

I am setting up a architecture for a new project. For this project we are using Sitecore 7 CMS. As you may know, Sitecore supports a multi-site environement. This means that 1 IIS instance can be used for multiple sites because Sitecore resolves them to use the right code and content.

For this project I will have the following hierarchy:

  • Core (generic, site unspecific logic)
    • Website A
    • Website B

We should be able to add as many sites as we want. Every site has a Data, Business and Presentation layer.

I also want to use a IoC container such as Castle Windsor, Ninject or Unity. I want a generic container/kernel for the core and then I would like to be able to register class for specific sites. So the classes I register for Website A should not be resolved for Website B

In Unity I guess you could child containers. I did not find a good way to force the application to use the child container when the Sitecore Context meets a certain requirement.

In Ninject I found stuff on contextual bindings, named scopes and modules which I liked very much. I thought I create a NinjectModule with Contextual Bindings and on resolving I would check the context. I did not find a nice and generic way of doing this.

However, after hours of googling I did not find a good example or tutorial on how this could be achieved and how this should be done in the best way.

For now I do not have a preference for which framework I want to use.

Hope some one would shed some light for my problem so that I can make some progress. Thanks in advance

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
Hans Leautaud
  • 1,742
  • 1
  • 19
  • 34
  • For referece, you can achieve a lot of this with Sitecore itself http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/02/The-Sitecore-ASPNET-CMS-Configuration-Factory.aspx – Martin Davies Apr 21 '14 at 16:52
  • 1
    Since each site will most likely run for the most part in isolation, the most maintainable solution will be to have one container per site and extract the duplicate registrations into a reusable method that makes the shared registrations. – Steven Apr 22 '14 at 08:40

2 Answers2

2

Look in to Windsor's Handler Selectors. They're a nice solution to multi-tenant applications. Also, Mike Hadlow has a couple of posts about using Handler Selectors in a multi-tenant environment.

PatrickSteele
  • 14,489
  • 2
  • 51
  • 54
  • Thank you. Howerver, this means I should create a handler selector for each object i would like to resolve isn't it. I also found: https://code.google.com/p/autofac/wiki/MultitenantIntegration which looks pretty much what I need. – Hans Leautaud Apr 22 '14 at 06:39
  • In Ninject this could also be a solution: a.Bind().To().When(x => Sitecore.Context.GetSiteName() == "Sitename"); – Hans Leautaud Apr 22 '14 at 06:43
  • You would just need a handler selector for those components that need to be context-aware. Some may have dependencies that need to be context-aware, but they wouldn't need a handler selector. – PatrickSteele Apr 22 '14 at 11:25
1

I resolved it by using Multi-tenancy in Autofac: https://code.google.com/p/autofac/wiki/MultitenantIntegration

Hans Leautaud
  • 1,742
  • 1
  • 19
  • 34