Service Container C#

Topics: Subroutine, Object-oriented programming, Java Pages: 2 (432 words) Published: November 28, 2012
Service Container
Presented by: Anton Cherkasov
Service Providers
§Services are the basic building blocks of the .NET design-time architecture. They help to expose access to specific features from external objects.

§Designers and components can obtain other services through the use of service providers. A.NET service provider is represented by the System.IServiceProvider interface. The interface provides a mechanism for retrieving a specific service object, given the type of object to retrieve. Here is the only member of this interface:

object GetService(Type serviceType)

This method, when overridden, will return 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 Interface
§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 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. void AddService(Type serviceType, object service);
void 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. void RemoveService(Type serviceType);
void RemoveService(Type serviceType, bool promote); 
ServiceContainer Class
§The .NET Framework comes with a class that is...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • C Essay
  • service sector Research Paper
  • Essay about Community Service
  • Service Diary Essay
  • Services Essay
  • C++ HW1 ANSWER Essay
  • C++ solution Essay
  • Stone Container Essay

Become a StudyMode Member

Sign Up - It's Free