X

Register now for unlimited access to Sitecore resources.


Already have an account? Log in now

*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
X

Request a demo

It’s easy to get started. Sign up for a personalized demo.

*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
Sitecore Blog: Sitecore 7 Development Team

Using an IOC Container with SOLR

By Sitecore 7 Development Team, July 09, 2013 | Rating:  | Comments (5)

Sitecore + Solr – Reusing an existing IOC container

One of the things you need, when you setup Sitecore 7 with Solr, is to choose an IOC container. This is a large subject fraught with many opinions. The great thing about current container market is that there is so much competition in the IOC space most of the major IOC containers offer identical features and often it’s just down to the syntax that you like the most.

Sitecore 7 supports the following containers:

  • Castle Windsor (http://www.castleproject.org/)
  • Structure Map (http://docs.structuremap.net/)
  • Ninject (http://www.ninject.org/)
  • AutoFac (http://autofac.org/)
  • Unity (http://unity.codeplex.com/)

You can find the support DLLs for each in the ‘Solr Support Package’ (which isn’t a Sitecore package, it’s just a zip!) found here.

Note: Please check the documentation to see which versions are supported in this release.

Plugging in the container

But what happens if you already have an existing container and want to use it as part of your new Sitecore 7 solution? Well the answer is: you’re in luck.

If you remember, when you setup the Global.asax class we swap the default Sitecore.Web.Application class for the one that matches our container (I will use Castle Windsor as my example container going forward) e.g Sitecore.ContentSearch.SolrProvider.CastleWindsorIntegration.WindsorApplication.

The actual application is very simple and just provides a simple quick start so you don’t have to copy code into your Global.asax file unnecessarily.

This is the code ..

Code

The important thing with containers is that there should be, if possible, only one instance of them in an application.

If you already have container setup code you can override the Application_Start method of this application, set up your container as normal and then pass it directly into the SolrStartUp method (e.g. WindsorSolrStartUp() ).

Sitecore also sets up a ServiceLocator for each container which you can resolve objects via ServiceLocator.Current.GetInstance<IYourService> .. or you can access the container from the global web application by using the public property ‘Container’.

Note: The only container that doesn’t follow this pattern is StructureMap as it uses the static ObjectFactory

There are lots of options here and you should find one that suits your setup but it should enable you to have friction-free setup of your application container with Sitecore 7.

  • Dev Team

Tags: Sitecore 7

Comments

  • Hi, I followed all the steps mentioned in the Search Scaling Guide (sitecore 7) for setting up Solr, but i am getting this error (i am using the Castle Windsor container)

    Method not found: Void Sitecore.ContentSearch.AbstractSearchFieldConfiguration..ctor(System.String, System.String, System.String, syste.Collections.Generic.IDictionary 2<System.String>/ System.Xml.XmlNode)on the WindorSolrstartup.Initialize()
    I am using Solr 4.5.1

    - Jigisha Dhawan
    November 04, 2013 at 12:57 PM

  • Does Sitecore 7 supports Solr 4.5.1 version?

    - Pooja Mittal
    November 26, 2013 at 7:09 PM

  • After setting up Solr i am getting this error:
    Method not found: Void Sitecore.ContentSearch.AbstractSearchFieldConfiguration..ctor(System.String, System.String, System.String, syste.Collections.Generic.IDictionary 2<System.String>/ System.Xml.XmlNode)on the WindorSolrstartup.Initialize()

    - vikas Rathore
    April 11, 2014 at 12:33 AM

  • Even I am gettin the same error. Someone Please help!

    - hemant keshri
    May 08, 2014 at 4:32 AM

  • I get the following error also.

    Method 'set_PropertyStore' in type 'Sitecore.ContentSearch.SolrProvider.SolrSearchIndex' from assembly 'Sitecore.ContentSearch.SolrProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

    - Michael Lam
    June 06, 2014 at 2:16 PM

*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.
Cookies help us improve your website experience. By using our website, you agree to our use of cookies. OK Learn more