haison8x / mediatr.simpleinjector Goto Github PK
View Code? Open in Web Editor NEWMediatR.SimpleInjector
License: Apache License 2.0
MediatR.SimpleInjector
License: Apache License 2.0
Hello,
just wanted to double check this is being maintained and used in production.
Hi
According to the Mediatr Simple injector examples, notification handlers should be registered as following :
container.Collection.Register(typeof(INotificationHandler<>), notificationHandlerTypes);
instead of :
container.Register (typeof (INotificationHandler<>), notificationHandlerTypes);
.
I will create PR regarding to this later.
Reference:
https://github.com/jbogard/MediatR/blob/master/samples/MediatR.Examples.SimpleInjector/Program.cs
Have you considered targeting .netstandard? It builds fine if I target 1.1.
Hi,
new version of mediator 6.0.0 supports only netstandard2.0 and .net framework 4.6.1.
I can prepare pull request for that.
Please consider major bump in version as this is breaking change for people still using .net 4.6 and .netstandard1.3 compatible version.
When call BuildMediator extension method like this:
container.BuildMediator(typeof(TestCommand).GetTypeInfo().Assembly);
it always call itself (version with params), and eventually raise StackOverflowException.
Simple injector RegisterCollection doesn't register the generic types from the assemblies. So passing IPipelineBehavior assemblies won't add any registration. Maybe those binding should be removed?
MediatR v10 introduced breaking changes: https://github.com/jbogard/MediatR/wiki/Migration-Guide-9.x-to-10.0
As a result MediatR.SimpleInjector 9.0 doesn't work with MediatR 10
Calling 'container.BuildMediator()' throws an exception Field not found: 'SimpleInjector.Lifestyle.Singleton'
using the latest SimpleInjector V5.0.
Can you check out the latest version of SimpleInjector and migrate your library?
https://github.com/simpleinjector/SimpleInjector/releases/tag/v5.0.0
RequestHandler and AsyncRequestHandler without output registers are not made.
Faced that issue in one of my projects
PR created for that purpose
Hi,
could you please choose license under which you distribute that package?
Thanks
Adam
I'm getting the following error when trying to send a command with mediatr.
SimpleInjector.ActivationException: The constructor of type RequestPreProcessorBehavior<AuthenticateClientCommand, AuthenticateClientResponse> contains the parameter with name 'preProcessors' and type IEnumerable<IRequestPreProcessor<AuthenticateClientCommand>>,
but IEnumerable<IRequestPreProcessor<AuthenticateClientCommand>> is not registered.
For IEnumerable<IRequestPreProcessor<AuthenticateClientCommand>> to be resolved, it must be registered in the container.
You can use one of the Container.Collection.Register overloads to register a collection of IRequestPreProcessor<AuthenticateClientCommand> types, or one of the Container.Collection.
Append overloads to append a single registration to a collection. In case you intend to resolve an empty collection of IRequestPreProcessor<AuthenticateClientCommand> elements,
make sure you register an empty collection; Simple Injector requires a call to Container.
Collection.Register to be made, even in the absence of any instances.
Please see https://simpleinjector.org/collections for more information about registering and resolving collections.
at SimpleInjector.Container.ThrowParameterTypeMustBeRegistered(InjectionTargetInfo target)
at SimpleInjector.Advanced.DefaultDependencyInjectionBehavior.GetInstanceProducer(InjectionConsumerInfo dependency, Boolean throwOnFailure)
at SimpleInjector.ContainerOptions.GetInstanceProducerFor(InjectionConsumerInfo consumer)
at SimpleInjector.Registration.BuildConstructorParameters(ConstructorInfo constructor)
at SimpleInjector.Registration.BuildNewExpression()
at SimpleInjector.Registration.BuildTransientExpression()
at SimpleInjector.Lifestyles.TransientLifestyle.TransientRegistration.BuildExpression()
at SimpleInjector.InstanceProducer.BuildExpressionInternal()
at SimpleInjector.Internals.LazyEx`1.InitializeAndReturn()
at SimpleInjector.InstanceProducer.BuildInstanceCreator()
at SimpleInjector.InstanceProducer.BuildAndReplaceInstanceCreatorAndCreateFirstInstance()
at SimpleInjector.InstanceProducer.GetInstance()
at SimpleInjector.Internals.ContainerControlledCollection`1.CopyTo(TService[] array, Int32 arrayIndex)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source, Int32& length)
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ReverseIterator`1.MoveNext()
at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
at MediatR.Internal.RequestHandlerWrapperImpl`2.Handle(IRequest`1 request, CancellationToken cancellationToken, ServiceFactory serviceFactory)
at MediatR.Mediator.Send[TResponse](IRequest`1 request, CancellationToken cancellationToken)
at WolvePack.HowlApi.Controllers.AuthenticationController.AuthenticateClient(AuthenticateClientCommand request) in AuthenticationController.cs:line 24
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at CorrelationId.CorrelationIdMiddleware.Invoke(HttpContext context, ICorrelationContextFactory correlationContextFactory)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
I'm not using any preprocessors.
Command and handler look like this:
public class AuthenticateClientCommand : IRequest<AuthenticateClientResponse>
{
public Guid Id { get; set; }
public string Secret { get; set; }
}
public class AuthenticateClientCommandHandler : IRequestHandler<AuthenticateClientCommand, AuthenticateClientResponse>
{
public async Task<AuthenticateClientResponse> Handle(AuthenticateClientCommand request, CancellationToken cancellationToken)
{
// code here
}
}
Configure with:
container.BuildMediator(<assemblies with query and commands here>);
When i take your source code and comment the following lines it works (but probably without some functionality):
container.Collection.Register(typeof(IPipelineBehavior<,>), new[]
{
typeof(RequestExceptionProcessorBehavior<,>),
typeof(RequestExceptionActionProcessorBehavior<,>),
//typeof(RequestPreProcessorBehavior<,>),
//typeof(RequestPostProcessorBehavior<,>)
});
Am I missing some configuration or is this project not fully compatible with the latest SimpleInjector? I know there are some breaking changes in 5.x.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.