Hi- The following code solved the DI Problem. Can you please check but I am getting a different error explained below. I will also post the code that causes the problem
public static IHostBuilder CreateHostBuilder(string[] args)
{
var abpBootstrapper = AbpBootstrapper.Create<CalculatorSchedulerModule>();
abpBootstrapper.Initialize();
return Host.CreateDefaultBuilder(args)
.UseWindowsService()
.UseCastleWindsor(abpBootstrapper.IocManager.IocContainer)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<CalculatorScheduler>();
});
}
** Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances. Object name: 'FPEDbContext'.**
We have a requirement where for users of certain role, they need to be redirected to a different portal , with different theme settings etc..although they might belong to the same tenant.
What are the configuration changes required to support 2 different front ends ( with different navigation, theme etc, ) for the same tenant using the same API layer ( Application).
Do I have to deploy as a seperate web app for the 2 front ends ? .Please advise. How much of a change will be required to support this requirement ?.
Also advise on the procedure to do it..
System.AggregateException
HResult=0x80131500
Message=Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.Extensions.Hosting.IHostedService Lifetime: Singleton ImplementationType: CalculatorSchedulerService.CalculatorScheduler': Unable to resolve service for type 'Abp.Domain.Repositories.IRepository2[SEB.FPE.Calculators.CalculatorProfile,System.Int32]' while attempting to activate 'SEB.FPE.Calculators.Jobs.CalculatorProfileJob'.) (Error while validating the service descriptor 'ServiceType: SEB.FPE.Calculators.Jobs.ICalculatorProfileJob Lifetime: Singleton ImplementationType: SEB.FPE.Calculators.Jobs.CalculatorProfileJob': Unable to resolve service for type 'Abp.Domain.Repositories.IRepository
2[SEB.FPE.Calculators.CalculatorProfile,System.Int32]' while attempting to activate 'SEB.FPE.Calculators.Jobs.CalculatorProfileJob'.)
Source=Microsoft.Extensions.DependencyInjection
StackTrace:
at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable1 serviceDescriptors, ServiceProviderOptions options) at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options) at Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory.CreateServiceProvider(IServiceCollection containerBuilder) at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter
1.CreateServiceProvider(Object containerBuilder)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at CalculatorSchedulerService.Program.Main(String[] args) in C:\Users\sesha.krishnamurthy\Source\repos\FPE\FPE\aspnet-core\src\CalculatorSchedulerService\Program.cs:line 41
This exception was originally thrown at this call stack: [External Code]
Inner Exception 1: InvalidOperationException: Error while validating the service descriptor 'ServiceType: Microsoft.Extensions.Hosting.IHostedService Lifetime: Singleton ImplementationType: CalculatorSchedulerService.CalculatorScheduler': Unable to resolve service for type 'Abp.Domain.Repositories.IRepository`2[SEB.FPE.Calculators.CalculatorProfile,System.Int32]' while attempting to activate 'SEB.FPE.Calculators.Jobs.CalculatorProfileJob'.
Inner Exception 2: InvalidOperationException: Unable to resolve service for type 'Abp.Domain.Repositories.IRepository`2[SEB.FPE.Calculators.CalculatorProfile,System.Int32]' while attempting to activate 'SEB.FPE.Calculators.Jobs.CalculatorProfileJob'.
I tried this but it is still complaining on dependency injection for CalculatorProfileJob. it is a domain service under "core" Project and it has dependencies injected into it ( like repositories). Looks like I have to inject the entire dependency hiearchy chain here which is not correct. Is there a way out ?.
You can try this just by creating a new .NET Core Worker service project and injecting any of Abp domain services into it
I guess the bootstrapper is still not taking care of dependency injection for the HostedService.
Hi The bootstrapper works fine for the Console Application. But here I am using a .NET Core Worker Service to be deployed as Windows Service . it uses "DefaultHostBuilder". The key here is how do I define a startup module and hook it into the Host builder. There seem to be no direct way of doing it. How do I inject abp IOC Container and dependencies into my Host Builder ? I can use services.AddSingleton() as in the example below, but I cannot add entire dependency chain individually in this fashion. The only way to add all dependencies through chain of execution of Modules for each assembly which will all be made dependent on my start up module.
Just like a Console Application example, Dont you have an example of Windows Service or Worker Service accessing all Abp's Application, Domain and Entityframework layer components ?. That would be useful..
My key problem is "How do I attach a Startup module to my Worker Service Host Builder". If I am able to do that I can hook dependencies to other Modules ( application, Core etc.) and get all the components into IOC container automatically.
How do I inject the entire dependency container of Abp in the code below ??
Host.CreateDefaultBuilder(args) .UseWindowsService()
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<CalculatorScheduler>();
services.AddSingleton<ICalculatorProfileJob, CalculatorProfileJob>();
});
Hi- Thanks for the information. I was able to get it working for a Console Application.
But I need to hookup a startup module to my .NET Core Worker service I am creating ( Windows Service ).
How do I hook up a start up module to my worker service using a default host builder. For e.g below
** it seems the extension method "AddAbp" is not available for a default Host Builder.**
"CalculatorSchedulerModule" is my custom start up module for my custom worker service and I have set the
dependency of that module to Core Module and Entity framework module.
I noticed that the extension method is part of namespace "Abp.AspNetCore". How do I reference that in my custom
worker service which I am planning to run as a Windows Service.
The below code is in "Program.cs".
Host.CreateDefaultBuilder(args)
.UseWindowsService()
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<CalculatorScheduler>();
** services.AddAbp<CalculatorSchedulerModule>();**
});
Hi- We are creating custom applications ( e.g say a Web API ) that would need to access ZERO Domain services, repositories, Dbcontext etc,..
What are the Project references that I would need to add to our custom application.
How do I inject all dependencies?.. I know in the web solution castle windsor takes care of all dependencies through dependency injection
Basically we would need access to all libraries except the application service layer for the custom application. The appSettings from our custom application need to be fed into all these dependencies ( e.g conn string etc,..).
Do you have any sample projects other than the ZERO web solution that access these libraries ?
Please let me know.
Regards, Sesha K
Hi- I added the sqllite version 3.1.1 and it worked fine in my local visual studio 2019.. The problem is specific to Azure Build/Deploy.
I am using VS 2019 and azure is also set up to use Agent windows-2019 and VS 2019 to build the web solution but is giving following error. Why is the web solution targeted for .netcoreapp3.1 needs "Microsoft.Build.Framework version 15.1.0.0" as below..
Have you tested your latest solution v8.4 with Azure pipeline using VS 2019 ? or do you have instructions for setting up azure pipeline for ZERO solution V 8.4
##[error]The nuget command failed with exit code(1) and error(Error parsing solution file at D:\a\10\s\TEST\aspnet-core\SEB.FPE.Web.sln: Exception has been thrown by the target of an invocation. The project file could not be loaded. Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. D:\a\10\s\TEST\aspnet-core\SEB.FPE.Web.sln)
HI- I have ASP.NET Core & Angular solution v 8.4 installed in my machine..
I am trying to set up Azure pipeline for the Web solution with targetframework .netcoreapp3.1.
The NUGET Restore command fails with below error. for the "Web.Host" and "Web.Public" Projects. However when I see dependencies on these 2 projects I do not see the Microsoft.EntityFrameworkCore.Sqlite package being referrenced at all.
#[error]The nuget command failed with exit code(1) and error(NU1202: Package Microsoft.EntityFrameworkCore.Sqlite 3.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.EntityFrameworkCore.Sqlite 3.0.0 supports: netstandard2.1 (.NETStandard,Version=v2.1)
Can you please tell if the package is being referenced in web.host or web.public ?. I cant see that it is being referenced
The Test Projects work fine. Please let us know.
Thanks