private ILogger CreateLogger(IComponentContext resolver) { var configurations = resolver.ResolveAll<LogSink.Configuration>(); var baseConfiguration = resolver.Resolve<LoggerConfiguration>(); return configurations.Aggregate(baseConfiguration, (_, configure) => configure(_)).CreateLogger(); }
public CQRSService( IGamePlayEngine gamePlayEngine, IGamePlayListener gamePlayListener, IReadCacheDataRepository readCacheDataRepository, IGameDataRepository gameDataRepository, ICqrsLogicHandler logicHandler, IEventPublisher eventPublisher, IComponentContext componentContext, ILogFactory logFactory ) : base(componentContext, logFactory) { _gamePlayEngine = gamePlayEngine; _gamePlayListener = gamePlayListener; _readCacheDataRepository = readCacheDataRepository; _gameDataRepository = gameDataRepository; _logicHandler = logicHandler; _handlers.AddRange( componentContext.ResolveAll <IHttpRequestHandler>() ); _log = logFactory.CreateForType(this); // Subscribe myself to any event eventPublisher.Attach(this); }
public override void Receive() { this.Respond(_components.ResolveAll <ActorSystem>() .Select(e => new { e.Name, e.StartTime, e.Uptime })); }
/// <inheritdoc /> public async Task <MessageResult> Dispatch(Request request, ExecutionContext context) { context = new ExecutionContext(request, context); var handlers = _components.ResolveAll(typeof(IHandle <>).MakeGenericType(request.Message.MessageType)); foreach (var handler in handlers) { typeof(IHandle <>).MakeGenericType(request.Message.MessageType).GetMethod("Handle").Invoke(handler, new[] { request.Message.Body }); } return(new MessageResult(context)); }
GetHandlers <TEvent>() { return(_context.ResolveAll <IEventHandler <TEvent> >() ?? new IEventHandler <TEvent>[] { }); }
/// <summary> /// Get all the registered handlers for the given type /// </summary> /// <param name="type">The type of the event to be processed</param> /// <returns>The collection of registered handlers for the given type</returns> protected override IEnumerable GetHandlers(Type type) { return(_context.ResolveAll(typeof(IEventHandler <>).MakeGenericType(type)) ?? new object[] { }); }
private IEnumerable <ILogger> GetLoggers() { return(_components.ResolveAll <ILogger>().Where(e => e != this)); }
GetInitialisersPerRequest <TRequest>() { return(_context .ResolveAll <IExecutionContextExtensionInitialiser <TRequest> >()); }
protected override void OnStart() { var allQueryHandlers = _componentContext.ResolveAll <IQueryHandler>(); var allCommandHandlers = _componentContext.ResolveAll <ICommandHandler>(); var allEventHandlers = _componentContext.ResolveAll <IEventHandler>(); foreach (var handler in allQueryHandlers) { // NOTE: It is possible that the same component can handle multiple requests. Get // all interfaces for the type to identify each of these abilities. Type[] genericInterfaces = handler.GetType().GetInterfaces(); foreach (var genericInterface in genericInterfaces) { // if (typeof(IQueryHandler) == genericInterface) { continue; } // If the interface is not derived from T, then ignore if (!typeof(IQueryHandler).IsAssignableFrom(genericInterface)) { continue; } var queryType = genericInterface.GetGenericArguments()[0]; var typeHashCode = genericInterface.GetHashCode(); if (!_queryHandlers.ContainsKey(typeHashCode)) { _queryHandlers.Add(typeHashCode, new HashSet <QueryHandlerItem>()); } // Create generic wrapper component var item = (QueryHandlerItem)_componentContext.Resolve( typeof(QueryHandlerItem <>).MakeGenericType(queryType), new PositionalParameter(0, handler) ); _queryHandlers[typeHashCode].Add(item); } } foreach (var handler in allCommandHandlers) { // NOTE: It is possible that the same component can handle multiple requests. Get // all interfaces for the type to identify each of these abilities. Type[] genericInterfaces = handler.GetType().GetInterfaces(); foreach (var genericInterface in genericInterfaces) { // if (typeof(ICommandHandler) == genericInterface) { continue; } // If the interface is not derived from T, then ignore if (!typeof(ICommandHandler).IsAssignableFrom(genericInterface)) { continue; } var commandType = genericInterface.GetGenericArguments()[0]; var typeHashCode = genericInterface.GetHashCode(); if (!_commandHandlers.ContainsKey(typeHashCode)) { _commandHandlers.Add(typeHashCode, new HashSet <CommandHandlerItem>()); } // Create generic wrapper component var item = (CommandHandlerItem)_componentContext.Resolve( typeof(CommandHandlerItem <>).MakeGenericType(commandType), new PositionalParameter(0, handler) ); _commandHandlers[typeHashCode].Add(item); } } foreach (var handler in allEventHandlers) { // NOTE: It is possible that the same component can handle multiple requests. Get // all interfaces for the type to identify each of these abilities. Type[] genericInterfaces = handler.GetType().GetInterfaces(); foreach (var genericInterface in genericInterfaces) { // if (typeof(IEventHandler) == genericInterface) { continue; } // If the interface is not derived from T, then ignore if (!typeof(IEventHandler).IsAssignableFrom(genericInterface)) { continue; } var eventType = genericInterface.GetGenericArguments()[0]; var typeHashCode = genericInterface.GetHashCode(); if (!_eventHandlers.ContainsKey(typeHashCode)) { _eventHandlers.Add(typeHashCode, new HashSet <EventHandlerItem>()); } // Create generic wrapper component var item = (EventHandlerItem)_componentContext.Resolve( typeof(EventHandlerItem <>).MakeGenericType(eventType), new PositionalParameter(0, handler) ); _eventHandlers[typeHashCode].Add(item); } } }