public static void AddImplementors <TFrom>(this IServiceProvider services)
        {
            var baseType             = typeof(TFrom);
            IEnumerable <Type> types =
                from a in AppDomain.CurrentDomain.GetAssemblies()
                from t in a.GetTypes()
                select t;

            var allTypes = types.ToList();

            var derivedTypes = allTypes.Where(t => baseType.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract);

            foreach (var derivedType in derivedTypes)
            {
                services.AddTransient <TFrom>(derivedType, derivedType.FullName);
            }
        }
Beispiel #2
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureServices(service => {
            service.AddDistributedRedisCache(options => {
                options.Configuration = Env.RedisConnString;
            });
            service.AddDbContext <SearchContext>(options => options.UseNpgsql(SearchContext.Configuring), ServiceLifetime.Transient);
            service.AddSingleton <ITelegramBotClient>(sp => string.IsNullOrEmpty(Env.HttpProxy) ? new TelegramBotClient(Env.BotToken) : new TelegramBotClient(Env.BotToken, new WebProxy(Env.HttpProxy)));
            service.AddTransient <SendService>();
            service.AddSingleton <SendMessage>();

            service.AddTransient <SonicSearchService>();
            service.AddTransient <SearchService>();
            service.AddTransient <MessageService>();
            service.AddTransient <AutoQRService>();
            service.AddTransient <AutoOCRService>();
            service.AddTransient <RefreshService>();
            AddController(service);
        });
Beispiel #3
0
 public static IServiceProvider AddHubContext <THub, THubClient>(this IServiceProvider services) where THub : IHub where THubClient : class
 {
     services.AddTransient <IHubContext <THubClient> >((s) => s.GetService <IConnectionManager>().GetHubContext <THub, THubClient>());
     return(services);
 }
Beispiel #4
0
 public static void AddCustomLogger(this IServiceProvider service)
 {
     service.AddTransient <LoggingMailService>();
 }