标签:ring play line esc let main opened cep data
class Program { static void Main(string[] args) { IServiceCollection serviceCollection = new ServiceCollection() .AddSingleton<IFoobar, Foo>() .AddSingleton<IFoobar, Bar>(); IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(); Console.WriteLine("serviceProvider.GetService(): {0}", serviceProvider.GetService<IFoobar>()); IEnumerable<IFoobar> services = serviceProvider.GetServices<IFoobar>(); Console.WriteLine("serviceProvider.GetServices():"); foreach (IFoobar foobar in services) { Console.WriteLine("{0}", foobar); } Console.ReadKey(); } } public interface IFoobar { } public class Foo : IFoobar { } public class Bar : IFoobar { }
serviceProvider.GetService(): AspnetCore02.Bar
serviceProvider.GetServices():
AspnetCore02.Foo
AspnetCore02.Bar
对比serviceProvider的GetService与GetServices
标签:ring play line esc let main opened cep data
原文地址:https://www.cnblogs.com/sunpan/p/14244062.html