Skip to main content
27 votes
Accepted

Best approach for Dependency Injection in Sitecore 8.2

There are three aspects in choosing a DI approach with Sitecore 8.2: The decision of which dependency injection container to use. The way you integrate the container with Sitecore and ASP.NET MVC. ...
Dmytro Shevchenko's user avatar
20 votes
Accepted

SimpleInjector as default DI in Sitecore 8.2

The problem with the simple injector container is that they do not provide a conforming container option. They don't like it. So to replace it with Simple Injector requires a bit more effort. In this ...
Richard Seal's user avatar
  • 20.7k
17 votes
Accepted

Dependency Injection migration path to 8.2

In my experience, when you plan major changes in your solution, the worst thing you can do is apply all of them at once. When you inevitably run into problems, you won't know which of the changes ...
Dmytro Shevchenko's user avatar
15 votes
Accepted

Sitecore Dependency Injection - register two abstractions to same singleton instance of an implementation

Same instance for multiple services I believe this can only be achieved with code registration: var implementation = new ServiceImplementation(); serviceCollection.AddSingleton<IService>(...
Dmytro Shevchenko's user avatar
15 votes

Best approach for Dependency Injection in Sitecore 8.2

I'm not entirely sure there is a "recommended" approach - it mostly boils down to the container you'd like to use and the features you'd like to leverage from that container. For instance, if you ...
LonghornTaco's user avatar
  • 2,536
13 votes
Accepted

Injecting dependencies into a custom WFFM save action

The WFFM module was significantly re-written in version 8.1+ and allows configuration driven dependency injection out of the box. For example, if you take a look at the /sitecore/system/Modules/Web ...
jammykam's user avatar
  • 13.9k
11 votes

Dependency Injection migration path to 8.2

One might think that there is already a similar question on this matter. However, your exact question is a bit different. An Upgrade Approach As far as unwiring the existing DI containers (and ...
Pete Navarra's user avatar
  • 14.7k
11 votes
Accepted

SXA custom component looking for parameterless constructor

To inject something via constructor or get types with Service Locator you need to register your services first. public class RegisterOoyalaServices : IocProcessor { public override void Process(...
Alan Płócieniak's user avatar
10 votes
Accepted

"No parameterless constructor defined for this object" after upgrade to Sitecore 8.2

The reason you are getting No parameterless constructor error is because Sitecore cannot create an instance of your controller that takes parameters. Without dependency injection working correctly, ...
Chris Auer's user avatar
  • 13.2k
10 votes
Accepted

Recursive upgradeable lock acquisitions not allowed in this mode exception while accessing Sitecore configuration while initiating the IoC container

Explanation Your configurator is run as a part of the DI container initialization. During that phase, you cannot use the Sitecore Factory, because, starting from Sitecore 8.2, Factory uses the DI ...
Dmytro Shevchenko's user avatar
10 votes
Accepted

Dependency Injection for Sitecore pipeline processor

Assuming you're running Sitecore 8.2 or later, you can add resolve="true" to the <pipeline> element to enable DI resolution for the processor. Sitecore uses Microsoft.Extensions....
Richard Szalay's user avatar
9 votes
Accepted

Should I reference Microsoft.Extensions.DependencyInjection in modules I create for Sitecore 8.2+?

When Sitecore gets reconfigured to use another container; will that container also be used to resolve these entries? It depends on how that other container gets configured, exactly. If you use the ...
Dmytro Shevchenko's user avatar
7 votes
Accepted

IoC in Helix architicture

I wrote a blog post on this here - here are the cliff notes. I'm going to assume Sitecore 8.2 for the version here, but the process is pretty much the same for earlier versions too, there would be ...
Richard Seal's user avatar
  • 20.7k
7 votes
Accepted

Singleton search context for search api

Is using a single, reused context a good approach? Yes. It is the recommended approach. Are there any pitfalls? Yes. New documents added to your indexes will not show, until you re-open a new Search ...
Mark Cassidy's user avatar
  • 25.4k
7 votes

How to register Glass Mapper ISitecoreService in my Ioc

I wanted to add this as the other answers are close, but not 100% IMO. First - SitecoreContext and SitecoreService have overloaded constructors. So you have to use a factory registration to be able ...
Richard Seal's user avatar
  • 20.7k
6 votes

SXA custom component looking for parameterless constructor

Ok - please don't use ServiceLocator to "fix" this issue. The problem looks to be because you have not registered your OoyalaController with your IoC container. If you are using the standard Sitecore ...
Richard Seal's user avatar
  • 20.7k
5 votes

Sitecore Dependency Injection - register two abstractions to same singleton instance of an implementation

You should be able to register the two interfaces to the same singleton instance implementation, but only in code, not in config. ServiceImplementation impl = new ServiceImplementation(); ...
Sean Holmesby's user avatar
5 votes
Accepted

Dependency Injection Not Wiring Up Properly When Optimize Code is Selected in Build

Thanks to @Jeroen and @Mark for helping to lead me in the right direction. Debugging locally, I found that the Assembly crawled in the AddMvcControllersInCurrentAssembly changes depending on ...
jrap's user avatar
  • 4,971
5 votes
Accepted

Custom submit action with constructor not working

Sitecore grabs the constructor with the signature it knows, i.e. the one with one parameter. If your submit-action doesn't have one, it'll fall back on the standard constructor of SubmitActionBase<...
asontu's user avatar
  • 181
4 votes
Accepted

Helix and Computed Index Fields with DI

Based on your comment above. You should move the definitions of those fields from the individual projects into a "Common" project in the Project Layer - you can then reference that in your individual ...
Richard Seal's user avatar
  • 20.7k
4 votes

Helix and Computed Index Fields with DI

Following the principles found in Helix, you should adhere to the Common Closure Principle: Classes that change together are packaged together. This means that you should define the computed index ...
Søren Engel's user avatar
  • 1,523
4 votes
Accepted

How to override/replace the default Sitecore Authentication Controller

The simplest solution here seems to be to update your custom controller A.B.Controllers.AuthenticationController to have a unique name so that it doesn't conflict with the Sitecore one. The risk of ...
Richard Seal's user avatar
  • 20.7k
4 votes

Best approach for Dependency Injection in Sitecore 8.2

A central challenge in respect to Habitat/Helix is the modular architecture - each module is self-contained and does not know of the other modules (and possibly the underlying framework). Kevin ...
Kasper's user avatar
  • 2,156
4 votes

Best approach for Dependency Injection in Sitecore 8.2

G Killian, I posted a question here about using SimpleInjector which you might find useful also: SimpleInjector as default DI in Sitecore 8.2 It contains a reply from Richard for how you go about ...
Adam Seabridge's user avatar
4 votes

Where can I find the instructions for setting up SOLR without using IOC?

In 8.2; SOLR support comes out of the box. You can optionally add your preferred DI container, but are not required to do so. The Sitecore Solr provider uses an IOC (Inversion of Control) ...
Mark Cassidy's user avatar
  • 25.4k
4 votes
Accepted

Sitecore Dependency Injection - Registering services with the lifetime of a web request

The default scope With Microsoft DI, the Scoped lifetime will default to a request scope in ASP.NET. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection#service-lifetimes-...
Dmytro Shevchenko's user avatar
4 votes
Accepted

Sitecore 8.2 memory leak with autofac DI on load test

We managed to identify the root cause of our memory leak. With help of MS and Sitecore, memory dump had lots of our controller and services hanging off of Root scope. By design the sitecore disposes ...
Nil Pun's user avatar
  • 2,313
4 votes
Accepted

How to make use of Autofac in IServicesConfigurator

There are 2 parts to how the MS Di Abstractions and Container are working in Sitecore. 1: The Configuration The config/configurators etc.. don't actually do the registration of the types with the ...
Richard Seal's user avatar
  • 20.7k
4 votes
Accepted

Inject parameters and an object into pipeline processor using DI

add a public variable with the parameter name and also modify the constructor to only accept the object that needs resolved: public string ExcludeSiteNames { get; set; } public PageNotFoundProcessor(...
gjakovaime's user avatar
3 votes

Can I use automatic dependency injection with computed search fields in Sitecore 8.1?

When you add a computed index field to the configuration, the section uses a certain method to instantiate resulting .Net objects for each computed field type: <fields hint="raw:...
Andrey Bobrov's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible