Closed. This question needs
CodePudding user response:
ConfigureService(IServiceCollection services)
wants an object that inherits from IServiceCollection. You are not really passing an interface as an param but an object with that interface.
CodePudding user response:
Interface as data types allow us to implement loose coupling between objects or classes. In your code above method, ConfiguresServices takes the input of type IServiceCollection interface.
Now there can be more than one class that implements the IServiceCollection interface. Say for example two classes Service1 & Service2 implements the interface IServiceCollection. With the parameter as IServiceCollection, we can set the variable to an instance of Service1 or Service2 class. (Now there are different methods or ways of providing this instance & this technique is known as Dependency Injection)
This way instead of direct dependency on class Service1 or Service2 method is dependent on interface IServiceCollection which allows injection of any class (service1 or Service2) that implements interface IServiceCollection