MediatR相关服务注入:
builder.RegisterAssemblyTypes(typeof(IMediator).GetTypeInfo().Assembly) .AsImplementedInterfaces(); // 注入IRequestHandler和INotificationHandler的相关实现 // Send -> RequestHandler // Publish -> NotificationHandler var mediatrOpenTypes = new[] { typeof(IRequestHandler<,>), typeof(IRequestHandler<>), typeof(INotificationHandler<>), }; foreach (var mediatrOpenType in mediatrOpenTypes) { builder .RegisterAssemblyTypes(typeof(MediatorModule).GetTypeInfo().Assembly) .AsClosedTypesOf(mediatrOpenType) .AsImplementedInterfaces(); } // 参照官网 builder.Register<SingleInstanceFactory>(context => { var componentContext = context.Resolve<IComponentContext>(); return t => { object o; return componentContext.TryResolve(t, out o) ? o : null; }; }); builder.Register<MultiInstanceFactory>(context => { var componentContext = context.Resolve<IComponentContext>(); return t => { var resolved = (IEnumerable<object>)componentContext.Resolve(typeof(IEnumerable<>).MakeGenericType(t)); return resolved; }; }); builder.RegisterGeneric(typeof(LoggingBehavior<,>)).As(typeof(IPipelineBehavior<,>)); 流程说明淘宝地址爬取及UI展示 (2)
内容版权声明:除非注明,否则皆为本站原创文章。