Closed dicksonkimeu closed 4 years ago
This is the class i want to call.
I was expecting something like this. but in vNext the IocManager is un recognized.
var workManager = IocManager.Resolve<IBackgroundWorkerManager>();
workManager.Add(IocManager.Resolve<BankingSwitchSync>());
You should check vnext's documentation. https://docs.abp.io/en/abp/latest/Dependency-Injection https://docs.abp.io/en/abp/latest
Have gone through the docs extensively, jobs are working (normal jobs) but can't see how to initialize my periodic background worker. Have been using something like this in the old framework
var workManager = IocManager.Resolve<IBackgroundWorkerManager>();
workManager.Add(IocManager.Resolve<BankingSwitchSync>());
context.ServiceProvider.GetRequiredService
Hello William, Where should I place this code ?
On the initialize of the module
You can override the OnApplicationInitializing
El El mar, 31 de diciembre de 2019 a la(s) 8:29 p.m., dicksonkimeu < notifications@github.com> escribió:
Hello William, Where should I place this code ?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/abpframework/abp/issues/2518?email_source=notifications&email_token=ACGJYYIW45AK76ED6CBBQJ3Q3P5W7A5CNFSM4KBQHRLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH4334Q#issuecomment-570015218, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACGJYYLK5SZXG4VWMXKEYGLQ3P5W7ANCNFSM4KBQHRLA .
--
Ing. William Obando Castellanos T: 351-123-7707
I don't seem to get this, would you help me with a sample code.
This is how I do it
I would suggest using resharper to find the right extension method, if this doesn’t work try
.GetService(typeof(IBackgroundService))
El El mié, 1 de enero de 2020 a la(s) 2:23 a.m., dicksonkimeu < notifications@github.com> escribió:
I don't seem to get this, would you help me with a sample code.
[image: image] https://user-images.githubusercontent.com/4476822/71639512-0852b080-2c89-11ea-891a-d67dd27c7a05.png
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/abpframework/abp/issues/2518?email_source=notifications&email_token=ACGJYYNAVLPMGCKWVEQWHPDQ3RHHFA5CNFSM4KBQHRLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH5AKXA#issuecomment-570033500, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACGJYYLHSJ2NVLQMHOLRQVLQ3RHHFANCNFSM4KBQHRLA .
--
Ing. William Obando Castellanos T: 351-123-7707
Have added this
context.ServiceProvider.GetService(typeof(IBackgroundWorkerManager));
context.ServiceProvider.GetRequiredService(typeof(BankingSwitchSync));
I was not able to add //context.ServiceProvider.GetRequiredService().Initialize();
When i ran the app i get error; Autofac.Core.Registration.ComponentNotRegisteredException: The requested service 'eBanking.VISA.Integration.BankingSwitchSync' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
hi @dicksonkimeu Try
public class Class : BackgroundWorkerBase
{
public override Task StartAsync(CancellationToken cancellationToken = default(CancellationToken))
{
this.Logger.LogDebug("Started background worker: " + this.ToString());
return Task.CompletedTask;
}
public override Task StopAsync(CancellationToken cancellationToken = default(CancellationToken))
{
this.Logger.LogDebug("Stopped background worker: " + this.ToString());
return Task.CompletedTask;
}
}
public class Class2 : PeriodicBackgroundWorkerBase
{
public Class2(AbpTimer timer) : base(timer)
{
timer.Period = 1000; //1s
}
protected override void DoWork()
{
this.Logger.LogDebug("Class2 => DoWork..");
}
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();
var env = context.GetEnvironment();
context.ServiceProvider.GetRequiredService<IBackgroundWorkerManager>().Add(context.ServiceProvider.GetRequiredService<Class>());
context.ServiceProvider.GetRequiredService<IBackgroundWorkerManager>().Add(context.ServiceProvider.GetRequiredService<Class2>());
//....
}
2020-01-02 11:40:50.485 +03:00 [FTL] Host terminated unexpectedly! Autofac.Core.Registration.ComponentNotRegisteredException: The requested service 'eBanking.VISA.Integration.Class' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
Please share the relevant code.
Have tried in OnApplicationInitialization and the results are the same.
context.ServiceProvider.GetRequiredService<IBackgroundWorkerManager>().Add(context.ServiceProvider.GetRequiredService<BankingSwitchSync>());
context.ServiceProvider.GetRequiredService<IBackgroundWorkerManager>().Add(context.ServiceProvider.GetRequiredService<Class>());
Please share a project to reproduce your problem, you can use cli to create a project.
Maybe add ISingletonDependency to Class and change OnApplicationInitialization to OnPostApplicationInitialization
El El jue, 2 de enero de 2020 a la(s) 2:44 a.m., maliming < notifications@github.com> escribió:
Please share a project to reproduce your problem, you can use cli to create a project.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/abpframework/abp/issues/2518?email_source=notifications&email_token=ACGJYYMFJD7UL6WPEOGYXW3Q3WSNLA5CNFSM4KBQHRLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH532QI#issuecomment-570146113, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACGJYYJH3W7PQJQU6PAUQA3Q3WSNLANCNFSM4KBQHRLA .
--
Ing. William Obando Castellanos T: 351-123-7707
hi @wocar
BackgroundWorkerBase
=> IBackgroundWorker
=> ISingletonDependency
@dicksonkimeu You can share the project on github.
@dicksonkimeu Try adding an IntegrationModule.
@maliming @hikalkan this is working fine now, but i have this error when i run a service with DB operations in my Integration Module #2601
@dicksonkimeu Please discuss it in a new issue.
This is how we used to call background service classes.
in vNext the IocManager is un recognized. what am i missing here ?