Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
eventbus refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
trendyol-bot committed Mar 1, 2017
1 parent 87a7a2f commit c681b34
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Stove/Events/Bus/EventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ namespace Stove.Events.Bus
/// </summary>
public class EventBus : IEventBus
{
/// <summary>
/// Gets the default <see cref="EventBus" /> instance.
/// </summary>
public static EventBus Default = new EventBus();

/// <summary>
/// All registered handler factories.
/// Key: Type of the event
Expand Down
13 changes: 13 additions & 0 deletions src/Stove/StoveCoreRegistrationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ public static IIocBuilder UseStoveEventBus([NotNull] this IIocBuilder builder)
return builder;
}


/// <summary>
/// Uses the stove default event bus.
/// </summary>
/// <param name="builder">The builder.</param>
/// <returns></returns>
[NotNull]
public static IIocBuilder UseStoveDefaultEventBus([NotNull] this IIocBuilder builder)
{
builder.RegisterServices(r => r.Register<IEventBus>(context => EventBus.Default, Lifetime.Singleton));
return builder;
}

/// <summary>
/// Uses the stove background jobs.
/// </summary>
Expand Down
32 changes: 32 additions & 0 deletions test/Stove.Tests.SampleApplication/BasicRepository_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Stove.Domain.Repositories;
using Stove.Domain.Uow;
using Stove.Events.Bus;
using Stove.Events.Bus.Entities;
using Stove.Events.Bus.Handlers;
using Stove.Extensions;
Expand Down Expand Up @@ -90,6 +91,37 @@ public void uow_complete_handle_eventbus_should_work_with_repository_insert()
}
}

[Fact]
public void uow_complete_handle_eventbus_should_work_with_repository_insert2()
{
var uowManager = LocalResolver.Resolve<IUnitOfWorkManager>();
var userRepository = LocalResolver.Resolve<IRepository<User>>();

using (IUnitOfWorkCompleteHandle uow = uowManager.Begin())
{
for (var i = 0; i < 1000; i++)
{
userRepository.Insert(new User
{
Email = "[email protected]",
Surname = "Sykn",
Name = "Oğuz"
});
}

uow.Complete();
}

using (IUnitOfWorkCompleteHandle uow = uowManager.Begin())
{
userRepository.GetAll().ForEach(user => user.Surname = "Soykan");
userRepository.Count(x => x.Email == "[email protected]").ShouldBe(1000);
userRepository.FirstOrDefault(x => x.Email == "[email protected]").ShouldNotBeNull();

uow.Complete();
}
}

public class UserCreatedEventHandler : IEventHandler<EntityCreatedEventData<User>>,
IEventHandler<EntityUpdatedEventData<User>>,
ITransientDependency
Expand Down

0 comments on commit c681b34

Please sign in to comment.