Comments (5)
I've fixed the error by changing the registration to this
builder.RegisterSource(new ContravariantRegistrationSource());
builder.RegisterAssemblyTypes(typeof(IMediator).Assembly).AsSelf().AsImplementedInterfaces();
builder.Register<SingleInstanceFactory>(ctx =>
{
var c = ctx.Resolve<IComponentContext>();
return t => c.Resolve(t);
});
builder.Register<MultiInstanceFactory>(ctx =>
{
var c = ctx.Resolve<IComponentContext>();
return t => (IEnumerable<object>)c.Resolve(typeof(IEnumerable<>).MakeGenericType(t));
});
But now it doesn't work with async actions
The requested service 'MediatR.IAsyncRequestHandler`2[[OfficeManager.Features.People.Edit+Query, OfficeManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[OfficeManager.Features.People.Edit+Command, OfficeManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' 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.
from mediatr.
Hi @TDK1964
you need to also register on Autofac your handlers. Try adding the following line after:
builder.RegisterAssemblyTypes(assembly)
.AsClosedTypesOf(typeof(IRequestHandler<,>))
.AsImplementedInterfaces();
builder.RegisterAssemblyTypes(assembly)
.AsClosedTypesOf(typeof(IAsyncRequestHandler<,>))
.AsImplementedInterfaces();
builder.RegisterAssemblyTypes(assembly)
.AsClosedTypesOf(typeof(INotificationHandler<>))
.AsImplementedInterfaces();
builder.RegisterAssemblyTypes(assembly)
.AsClosedTypesOf(typeof(IAsyncNotificationHandler<>))
.AsImplementedInterfaces();
from mediatr.
@kappy thanks for the feedback.
I actually did this while I was waiting for replies and it seemed to work. Is this acceptable?
builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
.Where(t => t.Name.EndsWith("Handler"))
.AsImplementedInterfaces()
.InstancePerRequest();
from mediatr.
That is more a Autofac related case other than MediatR.
I don't know all the considerations about using the name string compare vs the type.
from mediatr.
@kappy, on a seprate note, do you know how to convert this the autofac?
private static IElementGenerator<T> GetGenerator<T>(T model) where T : class
{
var library = StructuremapMvc.ParentScope.CurrentNestedContainer.GetInstance<HtmlConventionLibrary>();
return ElementGenerator<T>.For(library, t => StructuremapMvc.ParentScope.CurrentNestedContainer.GetInstance(t), model);
}
from mediatr.
Related Issues (20)
- Question: Can multiple MediatR handlers be packaged into a single class HOT 3
- .NET8 upgrade from .NET Core 2.1 : Command cannot be used as type parameter 'TRequest' for 'IRequestHandler<TRequest>' HOT 3
- Irequest in library and handler in web api project HOT 2
- what use net8 aot publish HOT 2
- v12.3.0 Breaking Change HOT 28
- Question: Why IRequestExceptionHandler is not catching? HOT 3
- Question: How to register generic requests HOT 10
- Can't register generic handlers in latest version HOT 5
- Question: Why MediatR does not support ValueTasks ?
- Question: Why MediatR does not support ValueTasks ? HOT 3
- Generic Handler implementation only handles single generic argument and breaks existing implementations HOT 9
- Validation is not invoked when IRequest has no Result
- Handlers for interfaced notifications are not working as expected HOT 2
- AddOpenBehavior doesn't register pipeline behaviors with nested generic parameters HOT 1
- Is there support for response types as tuples? HOT 3
- #1048 and v12.4.0 breaks RequestExceptionProcessorBehavior HOT 2
- Behavior not able to get services with request from minimal api endpoints
- MediatR + Autofac NotificationHandler decorator pattern strange behaviour. HOT 5
- Error registering the generic handler type. HOT 4
- gpt
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mediatr.