OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.42k stars 2.4k forks source link

Unable to resolve service for type 'OrchardCore.ContentManagement.IContentManager' #3666

Closed brogits closed 5 years ago

brogits commented 5 years ago

I'm getting this error when activating my customer module/controller.

Any thoughts on this?

I also did try the following to add this on the StartUp but it still doesn't work.

services.AddScoped<IContentManager, DefaultContentManager>()


System.InvalidOperationException: Unable to resolve service for type 'OrchardCore.ContentManagement.IContentManager' while attempting to activate 'xxx.AuditLogs.Controllers.AuditLogController'.
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
   at lambda_method(Closure , IServiceProvider , Object[] )
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass4_0.<CreateActivator>b__0(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.Extensions.DependencyInjection.CommitSessionMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchardcore\src\OrchardCore\OrchardCore.Data\OrchardCoreBuilderExtensions.cs:line 150
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at OrchardCore.Modules.ModularTenantRouterMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchardcore\src\OrchardCore\OrchardCore\Modules\ModularTenantRouterMiddleware.cs:line 82
   at OrchardCore.Logging.SerilogTenantNameLoggingMiddleware.Invoke(HttpContext context) in C:\projects\orchardcore\src\OrchardCore\OrchardCore.Logging.Serilog\SerilogTenantNameLoggingMiddleware.cs:line 25
   at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchardcore\src\OrchardCore\OrchardCore\Modules\ModularTenantContainerMiddleware.cs:line 99
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)```
brogits commented 5 years ago

ContentModule just need to be activated for this to work

sebastienros commented 5 years ago

You might need to add a feature dependency in your manifest to prevent that from happening again.

brogits commented 5 years ago

You might need to add a feature dependency in your manifest to prevent that from happening again.

Hi @sebastienros , do you mean to say to add this into the recipe.json file under steps? or you a separate manifest.json.

It just that whenever we add a new module we have to clean our app_data and do the setup just for the new module to be enabled.

Right now all our modules we put it in the theme.recipe.json in our recipe project.

Again thanks for your time.

sebastienros commented 5 years ago

You created a new module, this module apparently requires the Content module to be enabled. So in the Manifest.cs file of your module just add a dependency to OrchardCore.Content such that when your module is enabled (via recipe) the Content module will also be.

Take a look at other modules' manifest files for some examples.