public static AppHoster UseRouter(this AppHoster hoster, IServiceProvider provider, Func <IEnumerable <Assembly> > getTargetAssembly = null) { var router = provider.GetService <RouterMiddleware>(); if (router == null) { throw new AppException(ExceptionCode.OperationFailed, $"cannot get instance of {nameof(RouterMiddleware)}"); } var allAssembly = getTargetAssembly?.Invoke()?.ToList(); if (allAssembly != null) { allAssembly.ForEach(target => router.RegistServices(target)); } hoster.AppBuilder.Use(() => router); return(hoster); }
public static AppHoster UseMiddleware <T>(this AppHoster hoster, IServiceProvider provider) where T : IMiddleware { hoster.AppBuilder.Use(() => provider.GetService <T>()); return(hoster); }
public static AppHoster UseMiddleware <T>(this AppHoster hoster, Func <T> getInstance) where T : IMiddleware { hoster.AppBuilder.Use(getInstance); return(hoster); }