Monday, March 11, 2019

Service Container C#

Service Container Presented by Anton Cherkasov Service Providers Services are the fundamental building blocks of the . fire design-time architecture. They help to expose access to specific features from out-of-door quarrys. Designers and components can obtain other dos through the use of help providers. A. NET renovation provider is represented by the System. IServiceProvider porthole. The interfaceprovides a mechanism for retrieving a specific service intent, given the type of object to retrieve.Here is the only member of this interface objectGetService(TypeserviceType) This method, when overridden, will return an object that represents the contract 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 Interface A service container allows for services to be added and removed to it. Therefore, external objects can concur more control over what a service provider exposes .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 two methods of this interface AddService This method adds the specified service to the service container. This method has four overloads. invalidate 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 two overloads. voidRemoveService(TypeserviceType) voidRemoveService(TypeserviceType, boolpromote) ServiceContainer Class The . NET Frame drop dead comes with a class that is already derived from IServiceCont ainer to be used with the room decorator 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 form a simple design fig that gives a lot of advantages. For example defecates weak binding between leaf node components and the services they use creates a simple repository and service discovery mechanism that allows easily scale the application (or part thereof). allows for lazy core of services, there is a method AddService overload, creating services, when they ask for the first time is an pick to static classes supports programming, based on contracts applicable to implement the service-factory suita ble to create an architecture that supports plug-ins. Questions?

No comments:

Post a Comment