Skip to content

Install mediator

Kirill edited this page Oct 23, 2020 · 2 revisions

From current assembly

services.AddMediator(mediator => mediator.RegisterPartsFromExecutingAssembly())

From assemblies

services.AddMediator(typeof(Class1).Assembly, typeof(Class2).Assembly)

Register concrete parts

services.AddMediator(typeof(PreProcessor), typeof(Handler))

Other installation options

services.AddMediator(mediator => mediator
     .RegisterNotification<MyNotification>() // register pipeline if parts already registered in ServiceCollection
     .RegisterRequest<MyRequest>() // register pipeline if parts already registered
     .RegisterParts(partTypes) // register mediator parts from array of types
     .RegisterParts(partAssemblies) // register mediator parts from array of assemblies
     .AsSingleton()); // define lifetime if required (default - scoped)

Performance

Method Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
MediatR 253.35 us 3.823 us 3.576 us 1.00 48.3398 1.4648 - 298.61 KB
Marble 54.38 us 0.467 us 0.414 us 0.21 4.9438 0.3662 - 30.58 KB