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.
...
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 ...
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 ...
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>(...
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 ...
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 ...
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 ...
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(...
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, ...
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 ...
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....
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 ...
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 ...
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 ...
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 ...
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 ...
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();
...
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 ...
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<...
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 ...
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 ...
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 ...
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 ...
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 ...
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)
...
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-...
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 ...
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 ...
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(...
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:...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
dependency-injection × 66pipelines × 6
glass-mapper × 5
autofac × 5
sitecore-forms × 4
configuration × 4
helix × 4
content-search × 3
controller × 3
sxa × 2
solr × 2
sitecore-api × 2
wffm × 2
indexing × 2
upgrade × 2
lucene × 2
federated-authentication × 2
habitat × 2
sitecore-services-client × 2
xdb × 1
sitecore-client × 1
sitecore-commerce × 1
jss × 1
powershell-extensions × 1
exm × 1