charlessolar / Aggregates.NET

.NET event sourced domain driven design model via NServiceBus and GetEventStore

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding EventStore to my endpoint fails

AbdoDabbas opened this issue · comments

Hi,
I'm trying to add EventStore to my endpoint but it's failing with this exception:

2020-08-02 14:08:42.505 ERROR Moving message '54a9f936-25fa-4eb0-afc6-ac0b00b7a829' to the error queue 'error' because processing failed due to an exception:
System.Collections.Generic.KeyNotFoundException: No item found in behavior context with key: Aggregates.UnitOfWork.IDomain
   at NServiceBus.Extensibility.ContextBag.Get[T](String key)
   at NServiceBus.Extensibility.ContextBag.Get[T]()
........

In the handler endpoint, I copied the code from the ToDo example (from the Domain\Endpoin.cs) to initialize the endpoint.
In the sender endpoint I modified the CommandToDomain method (copied it from Infrastructure\Extensions\BusExtensions.cs) to be like this:

public static async Task CommandToDomain<T>(this IMessageSession bus, T message, bool timeout = true) where T: MyBaseCommand
{
	try
	{
		var options = new SendOptions();
		options.SetDestination("DomainDestName");

		Task task = bus.Send(message, options);

		await Task
			.WhenAny(Task.Delay(TimeoutSeconds), task)
			.ConfigureAwait(false);

		if (task.IsFaulted && task.Exception != null)
			throw task.Exception.InnerException;

		if (!task.IsCompleted)
			throw new CommandTimeoutException("Command timed out");
	}
	catch (Exception ex)
	{
		// TODO: Logger
		throw;
	}
}

P.S:
I don't know if this is related but I even added the same Mutator used in the ToDo sample but request is not reaching MutateIncoming method at all.

I don't know what's missing or what should I specify in other files (as I said I copied the Endpoint.cs file to my project)

I realized that if I used NServiceBus version 7.2.4 it works well, while 7.3.0 doesn't, any advice?

@AbdoDabbas Thanks for the report and email! I will have to check it out strange that it works in 7.2.4..

I will update the packages on those apps and try it for myself.

@AbdoDabbas Looking over things my recommendation right now is to stay on version 7.2.4. 7.3 has some breaking changes I have to incorporate into Aggregates.Net itself

Should be pretty easy once I have some time to look at it and setup a test environment

Also if you use SimpleInjector beware updating it as there's breaking changes there too

Thanks a lot, @charlessolar .. what do you think if you can explain the issue and the fix maybe I can do the changes on behalf of you and do a commit (if I could manage to do the changes).

And I'm using StructureMap I think it's OK, no issues with 7.3.0 or 7.2.4.

Thanks for your work.

Ok got it - the NSB folks deprecated a feature component I was using to position registration of my internal stuff. Particular/NServiceBus#5493

I fixed that and a couple other breaking changes from EventStore and its good to go now.

One thing to note though if you are using the TodoMVC sample. Make sure FakeItEasy remains at version 5.4.0. Don't update to 6.0.0 or 5.4.1 / 5.5.0. AutoFixture and FakeItEasy folks are having issues keeping a stable api

This is really awsome, really appreciate the quick response and fix :) this library is the core of our system.

Glad you like it feel free to reach out for any other issues or questions!