Skip to content

Commit 6fbad88

Browse files
committed
fix typo for Kafka Bus #15
1 parent 0786bc1 commit 6fbad88

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/NetCoreKit.Infrastructure.Bus.Kafka/DispatchedEventBus.cs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,29 +142,27 @@ public async Task Subscribe<TMessage>(params string[] topics)
142142

143143
if (msg.Value == null) continue;
144144

145-
using (var scope = _serviceProvider.CreateScope())
146-
{
147-
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
148-
var noti = msg.Value.MapTo<TMessage, INotification>();
149-
150-
var msgField = msg.Value.Descriptor.FindFieldByName("Key");
151-
var msgValue = msgField.Accessor.GetValue(msg.Value);
152-
153-
var currentAssembly = Assembly.GetExecutingAssembly();
154-
var callerAssemblies = new StackTrace().GetFrames()
155-
.Select(x => x.GetMethod().ReflectedType.Assembly).Distinct()
156-
.Where(x => x.GetReferencedAssemblies().Any(y => y.FullName == currentAssembly.FullName));
145+
var keyField = msg.Value.Descriptor.FindFieldByName("Key");
146+
var key = keyField.Accessor.GetValue(msg.Value);
157147

158-
var initialAssembly = callerAssemblies.Last();
148+
var currentAssembly = Assembly.GetExecutingAssembly();
149+
var callerAssemblies = new StackTrace()
150+
.GetFrames()
151+
?.Select(x => x.GetMethod().ReflectedType?.Assembly).Distinct()
152+
.Where(x => x.GetReferencedAssemblies().Any(y => y.FullName == currentAssembly.FullName));
153+
var callerAssembly = callerAssemblies?.Last();
159154

160-
var notific = initialAssembly.DefinedTypes
161-
.FirstOrDefault(x => x.AssemblyQualifiedName.Contains(msgValue.ToString()));
155+
var notifyType = callerAssembly
156+
?.DefinedTypes
157+
.FirstOrDefault(x => x.AssemblyQualifiedName.Contains(key.ToString()));
162158

163-
var obj = (INotification)Activator.CreateInstance(notific);
159+
var notify = (INotification)Activator.CreateInstance(notifyType);
160+
var notifyInstance = Mapper.Map(msg.Value, notify);
164161

165-
var abc = Mapper.Map(msg.Value, obj);
166-
167-
await mediator.Publish(abc);
162+
using (var scope = _serviceProvider.CreateScope())
163+
{
164+
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
165+
await mediator.Publish(notifyInstance);
168166
}
169167
}
170168
}

0 commit comments

Comments
 (0)