protected DomainEventSubscriber() { Settings = new DomainEventSubscriberSettings(Context.System.Settings.Config); if (Settings.AutoSubscribe) { var type = GetType(); var asyncSubscriptionTypes = type .GetAsyncDomainEventSubscriberSubscriptionTypes(); var subscriptionTypes = type .GetDomainEventSubscriberSubscriptionTypes(); foreach (var subscriptionType in asyncSubscriptionTypes) { Context.System.EventStream.Subscribe(Self, subscriptionType); } foreach (var subscriptionType in subscriptionTypes) { Context.System.EventStream.Subscribe(Self, subscriptionType); } } if (Settings.AutoReceive) { InitReceives(); InitAsyncReceives(); } }
protected DomainEventSubscriber( DomainEventSubscriberSettings settings = null) { Logger = Context.GetLogger(); if (settings == null) { Settings = new DomainEventSubscriberSettings(Context.System.Settings.Config); } else { Settings = settings; } SubscriptionTypes = new List <Type>(); if (Settings.AutoSubscribe) { var type = GetType(); var asyncDomainEventSubscriptionTypes = type .GetAsyncDomainEventSubscriberSubscriptionTypes(); var domainEventsubscriptionTypes = type .GetDomainEventSubscriberSubscriptionTypes(); var subscriptionTypes = new List <Type>(); subscriptionTypes.AddRange(asyncDomainEventSubscriptionTypes); subscriptionTypes.AddRange(domainEventsubscriptionTypes); SubscriptionTypes = subscriptionTypes; foreach (var subscriptionType in SubscriptionTypes) { Context.System.EventStream.Subscribe(Self, subscriptionType); } } if (Settings.AutoReceive) { InitReceives(); InitAsyncReceives(); } Receive <UnsubscribeFromAll>(Handle); }
protected DomainEventSubscriber() { Settings = new DomainEventSubscriberSettings(Context.System.Settings.Config); var type = GetType(); if (Settings.AutoSubscribe) { var subscriptionTypes = type .GetDomainEventSubscriberSubscriptionTypes(); foreach (var subscriptionType in subscriptionTypes) { Context.System.EventStream.Subscribe(Self, subscriptionType); } } if (Settings.AutoReceive) { var subscriptionTypes = type .GetDomainEventSubscriberSubscriptionTypes(); var methods = type .GetTypeInfo() .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Where(mi => { if (mi.Name != "Handle") { return(false); } var parameters = mi.GetParameters(); return (parameters.Length == 1); }) .ToDictionary( mi => mi.GetParameters()[0].ParameterType, mi => mi); var method = type .GetBaseType("ReceiveActor") .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Where(mi => { if (mi.Name != "ReceiveAsync") { return(false); } var parameters = mi.GetParameters(); return (parameters.Length == 2 && parameters[0].ParameterType.Name.Contains("Func")); }) .First(); foreach (var subscriptionType in subscriptionTypes) { var funcType = typeof(Func <,>).MakeGenericType(subscriptionType, typeof(Task)); var subscriptionFunction = Delegate.CreateDelegate(funcType, this, methods[subscriptionType]); var actorReceiveMethod = method.MakeGenericMethod(subscriptionType); actorReceiveMethod.Invoke(this, new [] { subscriptionFunction, null }); } } }