aspnetboilerplate: Castle.MicroKernel.CircularDependencyException when resolving MvcRouteHandler

Hello! I got a question. Abp.Boilerplate, v 3.9.0 Why am i getting Castle.MicroKernel.CircularDependencyException on

app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "defaultWithArea",
                    template: "{area}/{controller=Home}/{action=Index}/{id?}");

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

with breaking on exceptions turned on? How do i get rid of it? As far as I understood, the exception is thrown when resolving MvcRouteHandler. Full exception message is

Dependency cycle has been detected when trying to resolve component 'Microsoft.AspNetCore.Razor.Language.RazorProjectEngine_143cff80-96bf-4aa2-80fc-af7373a01ca6'.
The resolution tree that resulted in the cycle is the following:
Component 'Microsoft.AspNetCore.Razor.Language.RazorProjectEngine_143cff80-96bf-4aa2-80fc-af7373a01ca6' resolved as dependency of
	component 'Microsoft.AspNetCore.Razor.Language.RazorEngine_e513da7d-e020-4ea6-925d-e4c5c69c3bee' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Razor.Internal.LazyMetadataReferenceFeature_5cbf1bf2-21ea-4c01-9186-70edda5f81ff' resolved as dependency of
	component 'Microsoft.AspNetCore.Razor.Language.RazorProjectEngine_143cff80-96bf-4aa2-80fc-af7373a01ca6' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Razor.Compilation.IViewCompilerProvider_08cd7c5c-c9cf-4a5e-a5aa-12aec9f1961b' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Razor.IRazorPageFactoryProvider_c1da251e-97e1-41d8-adc2-9d9ea0d9242c' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Razor.IRazorViewEngine_4bdad906-7788-4ff0-8bc0-4af945e4a625' resolved as dependency of
	component 'Microsoft.Extensions.Options.IConfigureOptions`1[[Microsoft.AspNetCore.Mvc.MvcViewOptions, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]]_ad494af2-5ab1-43d8-944f-8d612001e90b' resolved as dependency of
	component 'Microsoft.Extensions.Options.IOptionsFactory`1_ebc4dd86-b18c-422a-8986-a406cad4eb42' resolved as dependency of
	component 'Microsoft.Extensions.Options.IOptionsFactory`1_ebc4dd86-b18c-422a-8986-a406cad4eb42' resolved as dependency of
	component 'Microsoft.Extensions.Options.IOptions`1_d8f88dbb-e8a9-4196-abf8-9b7398343629' resolved as dependency of
	component 'Microsoft.Extensions.Options.IOptions`1_d8f88dbb-e8a9-4196-abf8-9b7398343629' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.ApplicationModels.IPageApplicationModelProvider_47b77ab4-c4c0-4b1f-b306-1dd46aa082be' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.IPageLoader_930a8b19-9481-41d1-b412-9ba32a232960' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Abstractions.IActionInvokerProvider_8784d307-44bc-4edb-8a61-f3127ad49b79' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Infrastructure.IActionInvokerFactory_4961e9f6-9ade-4a98-9e3e-4de3f80bac3c' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler_d7531031-381e-4ff3-b56c-3568a38854a3' which is the root component being resolved.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 27 (13 by maintainers)

Most upvoted comments

Try this:

  1. Create AbpPropertiesDependenciesModelInspector class as shown below:
using Castle.Core;
using Castle.MicroKernel.ModelBuilder.Inspectors;
using Castle.MicroKernel.SubSystems.Conversion;

namespace Abp.Dependency
{
    public class AbpPropertiesDependenciesModelInspector : PropertiesDependenciesModelInspector
    {
        public AbpPropertiesDependenciesModelInspector(IConversionManager converter) 
            : base(converter)
        {
        }

        protected override void InspectProperties(ComponentModel model)
        {
            if (model.Implementation.FullName != null && 
                model.Implementation.FullName.StartsWith("Microsoft"))
            {
                return;
            }

            base.InspectProperties(model);
        }
    }
}
  1. Go to your Startup.cs, add following code in the services.AddAbp... options:
var propInjector = options.IocManager.IocContainer.Kernel.ComponentModelBuilder
    .Contributors
    .OfType<PropertiesDependenciesModelInspector>()
    .Single();

options.IocManager.IocContainer.Kernel.ComponentModelBuilder.RemoveContributor(propInjector);
options.IocManager.IocContainer.Kernel.ComponentModelBuilder.AddContributor(new AbpPropertiesDependenciesModelInspector(new DefaultConversionManager()));

See my commit for exact code: https://github.com/aspnetboilerplate/aspnetboilerplate/commit/1270e6766905994b69e1e2b8fe2d40ffeacb817d

If this works properly, we may include it into the framework. I know that Microsoft team ignores property injection, so the property injection shouldn’t work for Microsoft types.