Hi Zony, if I use the ReplaceService
the registred type is still overwritten by Abp.Quartz
and thus the IScheduler
is not properly configred. Am I missing something?
Furhermore, the Abp.Quartz.PreInitialize
calls indirectly the StdSchedulerFactory.GetDefaultScheduler()
, resulting in the creation of a default in-memory sheduler even before my custom PreInitialize
gets called. In this way I will end up with 2 different scheduler instances.
Ok, I've created the issue
Thank you.
Hi @ismcagdas, I've made may attempts. After UseAbp is not possibile beacause the extension method AddMediatR(...) is on IServiceCollection that isn't available on Configure method.
After looking at the examples and what does this extesion https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection, I ended up with this results:
Scenario: Framework and 2 plugin modules:
services.AddMediatR(typeof(Startup));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPreProcessorBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>));
IocManager.RegisterAssemblyByConvention(typeof(MyModule).GetAssembly());
IocManager.Register<IRequestHandler<PingCommand, string>, PingHandler>(DependencyLifeStyle.Transient); //Request/Response
IocManager.Register<IRequestHandler<PingCommandOneWay,Unit>, PingHandlerOneWay>(DependencyLifeStyle.Transient); //Request
IocManager.Register<INotificationHandler<PingNotification>, Pong1>(DependencyLifeStyle.Transient); //Notification
IocManager.Register<INotificationHandler<PingNotification>, Pong2>(DependencyLifeStyle.Transient); //Notification
//Pipelines
IocManager.IocContainer.Register(Component.For(typeof(IPipelineBehavior<,>)).ImplementedBy(typeof(LoggingBehavior<,>)).LifestyleTransient());
IocManager.IocContainer.Register(Component.For(typeof(IPipelineBehavior<,>)).ImplementedBy(typeof(ValidationBehaviour<,>)));
//Pre-Post processor IocManager.IocContainer.Register(Component.For(typeof(IRequestPreProcessor<>)).ImplementedBy(typeof(GenericPreProcessor<>)).LifestyleTransient());
IocManager.IocContainer.Register(Component.For(typeof(IRequestPostProcessor<,>)).ImplementedBy(typeof(GenericPostProcessor<,>)).LifestyleTransient());
//CatchAll notifications (See point no.3 for this)
IocManager.Register<INotificationHandler<INotification>, PongAll>(DependencyLifeStyle.Transient);
IocManager.IocContaine.Kernel.AddHandlersFilter(new ContravariantFilter());
public class ContravariantFilter : IHandlersFilter
{
public bool HasOpinionAbout(Type service)
{
if (!service.IsGenericType)
return false;
var genericType = service.GetGenericTypeDefinition();
var genericArguments = genericType.GetGenericArguments();
return genericArguments.Count() == 1
&& genericArguments.Single().GenericParameterAttributes.HasFlag(GenericParameterAttributes.Contravariant);
}
public IHandler[] SelectHandlers(Type service, IHandler[] handlers)
{
return handlers;
}
}
All this seems to works as expected, but is only a sort of cut&paste of AddMediatR with some Abp behaviours. I would be appreciate if you can officially integrate MediatR on Abp or at least validate how manually do.
Thank you very much.
Ok @ismcagdas
I'll look more deeply in Hangfire configuration.
I suppose your are interested too about this topic and I'll need your technical support to evaluate eventually changes to apply to AspNetZero in order to support multi instances.
It'll take some time and so for the moment I close the ticket.
Hi, some news about this topic? Is very important for a cloud based installation.
Thank you.
But, wait a moment. Hangfire is integrated in Aspnet zero, so, two instance of aspnet zero has two instance of hangfire. The problem is still alive.
Ok, That's a great thing !! I had missed this detail beacause we use quartz. Thank you.
Yess, is very easy.
Just follow the instrunction on this page:
https://docs.aspnetzero.com/en/aspnet-core-angular/latest/Infrastructure-Core-Angular-Identity-Server4-Integration
and use the console test program.
This is my configuration
"IdentityServer": { "IsEnabled": "true", "Authority": "https://localhost:44301/", "ApiName": "default-api", "ApiSecret": "secret", "Clients": [ { "ClientId": "client", "AllowedGrantTypes": [ "password" ], "ClientSecrets": [ { "Value": "def2edf7-5d42-4edc-a84a-30136c340e13" } ], "AllowedScopes": [ "default-api" ] }
Run Abp in debug mode and after start the console app. ValidateToken throw exception even if the request is correctly executed.
I must do a clarification about the question no 1.
The instances are created by Azure loadbalancer automatically and I don't know which and how many instances are running at same time. So is not possible apply your suggestion.
All background/jobs's system I think should have an interface like the Cache, so you can replace with a external well known scheduler service.
I've found it. thank you