Can't create component 'xxx.PortailWeb.PortailWebCoreModule' as it has dependencies to be satisfied. 'xxx.PortailWeb.PortailWebCoreModule' is waiting for the following dependencies: Service 'Microsoft.AspNetCore.Hosting.IWebHostEnvironment' which was not registered
See original GitHub issue- Your Abp package version : 5.13
- Your base framework: .Net Framework or .Net Core : 3.1
- Exception message and stack trace if available.
Can't create component 'xxx.PortailWeb.PortailWebCoreModule' as it has dependencies to be satisfied.
xxx.PortailWeb.PortailWebCoreModule' is waiting for the following dependencies:
Service 'Microsoft.AspNetCore.Hosting.IWebHostEnvironment' which was not registered
at Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency()
at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, Arguments additionalArguments, IReleasePolicy policy, Boolean ignoreParentContext)
at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, Arguments arguments, IReleasePolicy policy, Boolean ignoreParentContext)
at Castle.MicroKernel.DefaultKernel.Resolve(Type service, Arguments arguments)
at Castle.Windsor.WindsorContainer.Resolve(Type service)
at Abp.Dependency.IocManager.Resolve(Type type)
at Abp.Modules.AbpModuleManager.CreateModules(ICollection`1 moduleTypes, List`1 plugInModuleTypes)
at Abp.Modules.AbpModuleManager.LoadAllModules()
at Abp.Modules.AbpModuleManager.Initialize(Type startupModule)
at Abp.AbpBootstrapper.Initialize()
at xxx.PortailWeb.Migrator.Program.Main(String[] args) in C:\\xxxx\\code\\xxxx\\xxx.PortailWeb\\aspnet-core\\src\\bin\\xxxx.xxxx.Migrator\\Program.cs:line 27"
-
Steps needed to reproduce the problem. Running the Migrator project
-
Additional info
xxx.PortailWeb.Web.Core.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>1.0.0.0</VersionPrefix>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<AssemblyName>xxx.PortailWeb.Web.Core</AssemblyName>
<PackageId>xxx.PortailWeb.Web.Core</PackageId>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
<RootNamespace>xxx.PortailWeb</RootNamespace>
<LangVersion>7.2</LangVersion>
<Version>0.1.2.0</Version>
<Authors>xxx</Authors>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\xxx.PortailWeb.Application\xxx.PortailWeb.Application.csproj" />
<ProjectReference Include="..\xxx.PortailWeb.EntityFrameworkCore\xxx.PortailWeb.EntityFrameworkCore.csproj" />
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
<PackageReference Include="Abp.AspNetCore" Version="5.13.0" />
<PackageReference Include="Abp.ZeroCore" Version="5.13.0" />
<PackageReference Include="Abp.AspNetCore.SignalR" Version="5.13.0" />
</ItemGroup>
</Project>
PortailWebWebCoreModule
using System;
using System.IO;
using System.Text;
using Abp.AspNetCore.Configuration;
using Abp.AspNetCore.SignalR;
using Abp.Configuration.Startup;
using Abp.Modules;
using Abp.Reflection.Extensions;
using Abp.Zero.Configuration;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using xxx.PortailWeb.Configuration;
using xxx.PortailWeb.EntityFrameworkCore;
using xxx.PortailWeb.Authentication.JwtBearer;
using xxx.PortailWeb.Web.Configuration;
using Abp.AspNetCore;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
namespace xxx.PortailWeb
{
[DependsOn(
typeof(PortailWebApplicationModule),
typeof(PortailWebEntityFrameworkModule),
typeof(AbpAspNetCoreModule)
,typeof(AbpAspNetCoreSignalRModule)
)]
public class PortailWebWebCoreModule : AbpModule
{
private readonly IWebHostEnvironment _env;
private readonly IConfigurationRoot _appConfiguration;
public PortailWebWebCoreModule(IWebHostEnvironment env)
{
_env = env;
_appConfiguration = env.GetAppConfiguration();
}
public override void PreInitialize()
{
Configuration.DefaultNameOrConnectionString = _appConfiguration.GetConnectionString(
PortailWebConsts.ConnectionStringName
);
// Use database for language management
Configuration.Modules.Zero().LanguageManagement.EnableDbLocalization();
Configuration.Modules.AbpAspNetCore()
.CreateControllersForAppServices(
typeof(PortailWebApplicationModule).GetAssembly()
);
if (_appConfiguration["Authentication:JwtBearer:IsEnabled"] != null &&
bool.Parse(_appConfiguration["Authentication:JwtBearer:IsEnabled"]))
{
ConfigureTokenAuth();
}
Configuration.ReplaceService<IAppConfigurationAccessor, AppConfigurationAccessor>();
}
private void ConfigureTokenAuth()
{
IocManager.Register<TokenAuthConfiguration>();
var tokenAuthConfig = IocManager.Resolve<TokenAuthConfiguration>();
tokenAuthConfig.SecurityKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_appConfiguration["Authentication:JwtBearer:SecurityKey"]));
tokenAuthConfig.Issuer = _appConfiguration["Authentication:JwtBearer:Issuer"];
tokenAuthConfig.Audience = _appConfiguration["Authentication:JwtBearer:Audience"];
tokenAuthConfig.SigningCredentials = new SigningCredentials(tokenAuthConfig.SecurityKey, SecurityAlgorithms.HmacSha256);
tokenAuthConfig.Expiration = TimeSpan.FromDays(1);
}
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(typeof(PortailWebWebCoreModule).GetAssembly());
}
public override void PostInitialize()
{
IocManager.Resolve<ApplicationPartManager>()
.AddApplicationPartsIfNotAddedBefore(typeof(PortailWebWebCoreModule).Assembly);
}
}
}
Error occur when calling method bootstrapper.Initialize();
using System;
using Castle.Facilities.Logging;
using Abp;
using Abp.Castle.Logging.Log4Net;
using Abp.Collections.Extensions;
using Abp.Dependency;
namespace xxx.PortailWeb.Migrator
{
public class Program
{
private static bool _quietMode;
public static void Main(string[] args)
{
ParseArgs(args);
using (var bootstrapper = AbpBootstrapper.Create<PortailWebMigratorModule>())
{
bootstrapper.IocManager.IocContainer
.AddFacility<LoggingFacility>(
f => f.UseAbpLog4Net().WithConfig("log4net.config")
);
try
{
bootstrapper.Initialize();
using (var migrateExecuter = bootstrapper.IocManager.ResolveAsDisposable<MultiTenantMigrateExecuter>())
{
var migrationSucceeded = migrateExecuter.Object.Run(_quietMode);
if (_quietMode)
{
// exit clean (with exit code 0) if migration is a success, otherwise exit with code 1
var exitCode = Convert.ToInt32(!migrationSucceeded);
Environment.Exit(exitCode);
}
else
{
Console.WriteLine("Press ENTER to exit...");
Console.ReadLine();
}
}
}
catch (Exception ex)
{
Console.WriteLine("Couldn't run migration ...");
Console.WriteLine("--- MESSAGE ---");
Console.WriteLine(ex.Message);
Console.WriteLine("--- STACK TRACE ---");
Console.WriteLine(ex.StackTrace);
}
}
}
private static void ParseArgs(string[] args)
{
if (args.IsNullOrEmpty())
{
return;
}
foreach (var arg in args)
{
switch (arg)
{
case "-q":
_quietMode = true;
break;
}
}
}
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
c# - Can't create component as it has dependencies to be ...
Services.PQR.TestAppService' is waiting for the following dependencies: - Service 'ABC.XYZ.Business.Repositories.Interfaces.ITestRepository' ...
Read more >How to solve Can't create component as it has ...
PQR.TestAppService' is waiting for the following dependencies: - Service 'ABC.XYZ.Business.Repositories.Interfaces.ITestRepository' which was ...
Read more >Service 'Microsoft.AspNetCore.Hosting. ...
ProjectNameConnectionStringResolver' as it has dependencies to be satisfied. 'ProjectName.EntityFrameworkCore.
Read more >Dependency injection in ASP.NET Core
Learn how ASP.NET Core implements dependency injection and how to use it. ... Registration of the dependency in a service container. ASP.
Read more >Migrate from ASP.NET Core 2.2 to 3.0
This article explains how to update an existing ASP.NET Core 2.2 project to ASP.NET Core 3.0. It might be helpful to create a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, it’s what I’d like to do, but using IHostEnvironment. In the other modules IWebHostEnvironment is used, but I couldn’t make it work with any of them in the MigratorModule.
I ended up solving it by directly getting the ASPNETCORE_ENVIRONMENT variable from the system.
You can pass environment name to https://github.com/aspnetboilerplate/module-zero-core-template/blob/master/aspnet-core/src/AbpCompanyName.AbpProjectName.Core/Configuration/AppConfigurations.cs#L17