danielcirket / OpenEventSourcing

MIT License
3 stars 0 forks source link

Should the BackgroundProjector inherit from IHostedService? #2

Closed danielcirket closed 4 years ago

danielcirket commented 5 years ago

This would allow hosts, such as the ASP.NET Core WebHost or the generic host to easily run the background projectors as hosted services.

e.g.

services.AddHostedService<YourBackgroundProjectorAsHostedService>.

One things to consider is that this may impact how we handle projection registrations, being that the IHostedService implementations are run due to service registration. Doing an assembly scan to find the IProjector<> implementor(s) might not be optimal.

services.AddOpenEventSourcing()
             .AddProjections()
             ...

vs being more explicit:

services.AddOpenEventSourcing()
             .AddProjections(o => 
             {
                 o.AddProjection<YourBackgroundProjectorAsHostedService>();
                 o.<MethodName><YourBackgroundProjectorAsHostedService>();
             })
             ...

I'm leaning towards being explicit to allow for different projectors to be used, e.g. some projectors might want to be polling an event store and others using a push model of some description?

danielcirket commented 5 years ago

See overlapping details in issue #3