/// <summary> /// Initializes a new instance of the <see cref="MessageBusConfiguration"/> class. /// </summary> /// <param name="serviceProvider">The configured <see cref="IServiceProvider">service provider</see>.</param> /// <param name="clock">The configured <see cref="IClock">clock</see>.</param> /// <param name="persistence">The <see cref="IMapPersistence">mapping for persistence</see>.</param> /// <param name="messageSender">The configured <see cref="IMessageSender">message sender</see>.</param> /// <param name="messageReceiver">The configured <see cref="IMessageReceiver">message receiver</see>.</param> /// <param name="commandHandlerRegistrar">The configured <see cref="ICommandHandlerRegistrar">command handler registrar</see>.</param> /// <param name="eventReceiverRegistrar">The configured <see cref="IEventReceiverRegistrar">event handler registrar</see>.</param> /// <param name="sagaConfiguration">The <see cref="SagaConfiguration">saga configuration</see> used by the message bus.</param> /// <param name="uniqueIdGenerator">The configured <see cref="IUniqueIdGenerator">unique identifier generator</see> used by the message bus.</param> public MessageBusConfiguration( IServiceProvider serviceProvider, IClock clock, IMapPersistence persistence, IMessageSender messageSender, IMessageReceiver messageReceiver, ICommandHandlerRegistrar commandHandlerRegistrar, IEventReceiverRegistrar eventReceiverRegistrar, SagaConfiguration sagaConfiguration, IUniqueIdGenerator uniqueIdGenerator) { Arg.NotNull(serviceProvider, nameof(serviceProvider)); Arg.NotNull(clock, nameof(clock)); Arg.NotNull(persistence, nameof(persistence)); Arg.NotNull(messageSender, nameof(messageSender)); Arg.NotNull(messageReceiver, nameof(messageReceiver)); Arg.NotNull(commandHandlerRegistrar, nameof(commandHandlerRegistrar)); Arg.NotNull(eventReceiverRegistrar, nameof(eventReceiverRegistrar)); Arg.NotNull(sagaConfiguration, nameof(sagaConfiguration)); Arg.NotNull(uniqueIdGenerator, nameof(uniqueIdGenerator)); this.serviceProvider = serviceProvider; Clock = clock; Persistence = persistence; MessageSender = messageSender; MessageReceiver = messageReceiver; CommandHandlers = commandHandlerRegistrar; EventReceivers = eventReceiverRegistrar; Sagas = sagaConfiguration; UniqueIdGenerator = uniqueIdGenerator; }
/// <summary> /// Loads the module into the kernel. /// </summary> public override void Load() { Bind <IAkkaAggregateRepository <TAuthenticationToken> >().To <AkkaAggregateRepository <TAuthenticationToken> >().InSingletonScope(); Bind <IAkkaSagaRepository <TAuthenticationToken> >().To <AkkaSagaRepository <TAuthenticationToken> >().InSingletonScope(); Bind <IAkkaEventPublisher <TAuthenticationToken> >().To <AkkaEventBus <TAuthenticationToken> >().InSingletonScope(); Bind <IAkkaEventPublisherProxy <TAuthenticationToken> >().To <AkkaEventBusProxy <TAuthenticationToken> >().InSingletonScope(); Bind <IAkkaCommandPublisher <TAuthenticationToken> >().To <AkkaCommandBus <TAuthenticationToken> >().InSingletonScope(); Bind <IAkkaCommandPublisherProxy <TAuthenticationToken> >().To <AkkaCommandBusProxy <TAuthenticationToken> >().InSingletonScope(); BusRegistrar.GetEventHandlerRegistrar = (messageType, handlerDelegateTargetedType) => { bool isAnActor = messageType != null && messageType.GetNestedTypes().Any(type => type.Name == "Actor"); IEventHandlerRegistrar eventHandlerRegistrar = null; if (isAnActor) { eventHandlerRegistrar = Resolve <IAkkaEventPublisher <TAuthenticationToken> >() as IEventHandlerRegistrar; } return(eventHandlerRegistrar ?? Resolve <IEventHandlerRegistrar>()); }; BusRegistrar.GetCommandHandlerRegistrar = (messageType, handlerDelegateTargetedType) => { bool isAnActor = handlerDelegateTargetedType != null && handlerDelegateTargetedType.GetProperty("AggregateResolver", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public) != null; ICommandHandlerRegistrar commandHandlerRegistrar = null; if (isAnActor) { commandHandlerRegistrar = Resolve <IAkkaCommandPublisher <TAuthenticationToken> >() as ICommandHandlerRegistrar; } return(commandHandlerRegistrar ?? Resolve <ICommandHandlerRegistrar>()); }; }
/// <summary> /// Indicates the message bus configuration will have the specified command handler registrar. /// </summary> /// <param name="value">The configured <see cref="ICommandHandlerRegistrar">command registrar</see>.</param> /// <returns>The original <see cref="MessageBusConfigurationBuilder"/> instance.</returns> public virtual MessageBusConfigurationBuilder HasCommandHandlerRegistrar(ICommandHandlerRegistrar value) { Arg.NotNull(value, nameof(value)); Contract.Ensures(Contract.Result <MessageBusConfiguration>() != null); CommandRegistrar = value; CommandRegistrarIsOverriden = true; return(this); }