xerprojects / xer.cqrs.extensions.autofac Goto Github PK
View Code? Open in Web Editor NEWAutofac container integration for Xer.Cqrs
License: MIT License
Autofac container integration for Xer.Cqrs
License: MIT License
Hi!
Thanks for this cool library (Xer.Cqrs.CommandStack). I'm going to use it in one of my projects. But when I tried to integrate it with Autofac I got an exception. Let me show a sample code.
[Fact]
public async Task ShouldExecuteSampleCommand()
{
ContainerBuilder builder = new ContainerBuilder();
builder.RegisterCqrsCore()
.RegisterCommandHandlers(opt => opt.ByInterface(typeof(TestCommand).Assembly));
using (var context = builder.Build())
{
var commandDelegator = context.Resolve<CommandDelegator>();
var cmd = new TestCommand();
// act
await commandDelegator.SendAsync(cmd);
}
}
As you can see this is just one more unit test. The difference with other unit tests is that this one is not only assert "Command Delegator" not null but also use it to execute test command.
This unit test throws following exception:
Xer.Delegator.Exceptions.NoMessageHandlerResolvedException : Error occurred while trying to resolve message handler for TestCommand.
---- Xer.Delegator.Exceptions.NoMessageHandlerResolvedException : Error encoutered while trying to retrieve an instance of Xer.Cqrs.CommandStack.ICommandAsyncHandler`1[Xer.Cqrs.Extensions.Autofac.Tests.Entities.TestCommand] from the container.
-------- System.ObjectDisposedException : This resolve operation has already ended. When registering components using lambdas, the IComponentContext 'c' parameter to the lambda cannot be stored. Instead, either resolve IComponentContext again from 'c', or resolve a Func<> based factory to create subsequent components from.
at Xer.Delegator.Resolvers.RequiredMessageHandlerResolver.ResolveMessageHandler(Type messageType)
at Xer.Delegator.MessageDelegator.SendAsync[TMessage](TMessage message, CancellationToken cancellationToken)....
I've tested with Autofac version 4.9.2 and 4.6.2. In both cases I have this issue.
Use Lifetime enum as parameter to indicate handler instance lifetime.
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.