public async Task Ivoking_initializeasync_should_invoke_all_previously_added_initializers()
        {
            var firstInitializer   = new Mock <IStartupInitializer>();
            var secondInitializer  = new Mock <IStartupInitializer>();
            var startupInitializer = new StartupInitializer();

            startupInitializer.AddInitializer(firstInitializer.Object);
            startupInitializer.AddInitializer(secondInitializer.Object);
            await startupInitializer.InitializeAsync();

            firstInitializer.Verify(p => p.InitializeAsync(), Times.Once);
            secondInitializer.Verify(p => p.InitializeAsync(), Times.Once);
        }
Пример #2
0
        public static IServiceCollection AddInitializers(this IServiceCollection services, params Type[] initializers)
        => initializers == null
              ? services
              : services.AddTransient <IStartupInitializer, StartupInitializer>(c =>
        {
            var startupInitializer = new StartupInitializer();
            var validInitializers  = initializers.Where(t => typeof(IInitializer).IsAssignableFrom(t));
            foreach (var initializer in validInitializers)
            {
                startupInitializer.AddInitializer(c.GetService(initializer) as IInitializer);
            }

            return(startupInitializer);
        });