public static object Call(Type interfaceType) { var callerProvider = BusRouters.GetProviderToCallInternalInstance(interfaceType); if (queryClients.Count > 0) { if (queryClients.Keys.Contains(interfaceType)) { //Not a local call so apply cache layer at Bus level var providerCacheType = Discovery.GetImplementationType(interfaceType, iCacheProviderType, false); if (providerCacheType != null) { var methodSetNextProvider = TypeAnalyzer.GetMethodDetail(providerCacheType, nameof(BaseLayerProvider <IBaseProvider> .SetNextProvider)).MethodInfo; if (methodSetNextProvider != null) { var providerCache = Instantiator.GetSingleInstance($"{providerCacheType.FullName}_Bus.Call_Cache", () => { var instance = Instantiator.CreateInstance(providerCacheType); methodSetNextProvider.Invoke(instance, new object[] { callerProvider }); return(instance); }); return(providerCache); } } } } return(callerProvider); }
public static Task DispatchAsync(IEvent message) { Type messageType = message.GetType(); var messageTypeInfo = TypeAnalyzer.GetTypeDetail(messageType); if (commandClients.Count > 0) { //Not a local call so apply cache layer at Bus level var handlerType = TypeAnalyzer.GetGenericType(iEventHandlerType, messageType); var providerCacheType = Discovery.GetImplementationType(handlerType, iCacheProviderType, false); if (providerCacheType != null) { var methodSetNextProvider = TypeAnalyzer.GetMethodDetail(providerCacheType, nameof(BaseLayerProvider <IBaseProvider> .SetNextProvider)); if (methodSetNextProvider != null) { var providerCache = Instantiator.GetSingleInstance($"{providerCacheType.FullName}_Bus.DispatchAsync_Cache", () => { var instance = Instantiator.CreateInstance(providerCacheType); var methodGetProviderInterfaceType = TypeAnalyzer.GetMethodDetail(providerCacheType, nameof(BaseLayerProvider <IBaseProvider> .GetProviderInterfaceType)); Type interfaceType = (Type)methodGetProviderInterfaceType.Caller(instance, null); object messageHandlerToDispatchProvider = BusRouters.GetEventHandlerToDispatchInternalInstance(interfaceType); methodSetNextProvider.Caller(instance, new object[] { messageHandlerToDispatchProvider }); return(instance); }); var method = TypeAnalyzer.GetMethodDetail(providerCacheType, nameof(IEventHandler <IEvent> .Handle), new Type[] { messageType }); method.Caller(providerCache, new object[] { message }); return(Task.CompletedTask); } } } return(_DispatchEventInternalAsync(message, messageType)); }