0

We are using Unity for the dependency injection overriding the default behavior for the sitecore project. While deploying the jss app, I am getting below error.

The current type, Sitecore.JavaScriptServices.AppServices.Pipelines.Import.IImportPipeline, is an interface and cannot be constructed. Are you missing a type mapping?

when I try to resolve the dependency by registering the types by using below code, it leads to other errors which I am not sure is the right approach or not. How can I resolve the dependencies for types used in sitecore assemblies for successful deploying the app using Unity dependency injection.

        container.RegisterTypes(
            AllClasses.FromAssemblies(new[]
            {
                Assembly.Load("Sitecore.JavaScriptServices.AppServices"),
            }),
            WithMappings.FromMatchingInterface,
            WithName.Default, WithLifetime.PerResolve, null, true);

Thanks, Hashmat

0

First off why are you using Unity? If this is a new build I would look at taking advantage of the inbuilt container that Sitecore uses; if you want a more feature rich container checkout SimpleInjector or one of the other DI containers in the .NET echo system.

If in fact, you do need to use Unity, consider resolving the Sitecore dependencies you need from the Sitecore container with a focused adaptor rather than re-registering them, this has the advantage of not having to understand how Sitecore builds up its dependency graph.

I like the idea of an application container where you have dependencies registered for your application and call out to the Sitecore container when required to get Sitecore Dependencies. If you want some more thoughts and motivations behind this suggestion have a read of this blog article I published on the topic.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.