.

Friday, January 25, 2019

Service Container C#

Service Container Presented by Anton Cherkasov Service Providers Services are the basic building blocks of the . NET design-time architecture. They protagonist to expose access to limited features from external tendencys. Designers and components can obtain otherwise overhauls through the use of help suppliers. A. NET usefulness provider is represented by the System. IServiceProvider larboard. The interfaceprovides a mechanism for retrieving a specific service object, given the type of object to retrieve.Here is the only member of this interface objectGetService(TypeserviceType) This rule, when overridden, will beget an object that represents the specified service type. If the service provider cannot return an object of the specified type, then callers should expect the return value to be null. IServiceContainer larboard A service container allows for services to be added and removed to it. Therefore, external objects can have more control over what a service provider ex poses.A service container is actually a service provider. The interface that represents a service container is System. IServiceContainer, which is derived from IServiceProvider, as shown public interface IServiceContainer IServiceProvider IServiceContainer Interface Methods Here are the both(prenominal) methods of this interface AddService This method adds the specified service to the service container. This method has four overloads. void AddService(Type serviceType, object service) oid AddService(Type serviceType, ServiceCreatorCallback callback) void AddService(Type serviceType, object service, bool promote) void AddService(Type serviceType, ServiceCreatorCallback callback, bool promote) RemoveService This method removes the specified service from the service container. This method has twain overloads. voidRemoveService(TypeserviceType) voidRemoveService(TypeserviceType, boolpromote) ServiceContainer Class The . NET Framework comes with a secern that is already derived from IServiceContainer to be used with the designer framework.This class is System. ComponentModel. Design. ServiceContainer This class has two constructor overloads the default constructor, and one that takes a parent service provider as a parameter. This class uses a Hashtable to store the available services. It stores both service instances and service callbacks into this table for retrieval. How does it work? Pros The combination of services, providers, and service containers process a simple design pattern that gives a lot of advantages. For framework creates weak binding between client components and the services they use creates a simple repository and service discovery mechanism that allows easily exceed the application (or part thereof). allows for lazy loading of services, there is a method AddService overload, creating services, when they ask for the first time is an alternative to static classes supports programming, based on contracts applicable to implement the serv ice-factory suitable to create an architecture that supports plug-ins. Questions?

No comments:

Post a Comment