Registration class generic interface:
builder.RegisterAssemblyTypes(typeof(IEventHandler<>).Assembly) .Where(t => t.IsClass && t.GetInterfaces().Any(i=>i.IsGenericType && i.GetGenericTypeDefinition()==typeof(IEventHandler<>))) .AsSelf() .AsImplementedInterfaces();
Parsing generic interface:
var handlerType = typeof(IEventHandler<>).MakeGenericType(typeof(TEvent)); //TEvent是泛型 var handlerInstances = Activator.Invoke(typeof(IEnumerable<>).MakeGenericType(handlerType)) as IEnumerable;