C# Класс CK.Core.SimpleServiceContainer

Service container (that is a IServiceProvider) subordinated to an optional base IServiceProvider that acts as a fallback if the service is not found at this level. Service creation may be deferred thanks to callback registration and an optional remove callback can be registered with each entry.
This container is registered as the service associated to IServiceProvider and ISimpleServiceContainer thanks to the overridable GetDirectService. This method may be overridden to return other built-in services: these services take precedence over the registered services.
Наследование: ISimpleServiceContainer, IDisposable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
Add ( Type serviceType, Func serviceInstance, Action onRemove ) : ISimpleServiceContainer

Registers a service associated to a callback (and an optional callback that will be called when the service will be removed). The serviceInstance is called as long as no service has been obtained (serviceInstance returns null). Once the actual service has been obtained, it is kept and serviceInstance is not called anymore.

Add ( Type serviceType, object serviceInstance, Action onRemove ) : ISimpleServiceContainer

Registers a service with its implementation (and an optional callback that will be called when the service will be removed).

AddDisabled ( Type serviceType ) : ISimpleServiceContainer

Disables a service: null will always be returned by this IServiceProvider.GetService regardless of any fallbacks from BaseProvider. Direct services returned by GetDirectService can not be disabled.

This is not the same as calling Add(Type,Func{Object},Action{Object}) with a null instance. A null instance for a service (a callback that always returns null) is nearly the same as calling Remove: any fallbacks (to a base IServiceProvider for example) can occur. This is stronger since this must prevent fallbacks.

Clear ( ) : ISimpleServiceContainer

Unregisters all the services. Any "on remove" actions are executed.

Dispose ( ) : void

Disposing calls Clear to unregister all services. Any "on remove" actions are executed.

GetService ( Type serviceType ) : object

Implements IServiceProvider.GetService.

Remove ( Type serviceType ) : ISimpleServiceContainer

Unregisters a service. Can be called even if the service does not exist. The service is first removed and then the OnRemove associated action is called if it exists.

SimpleServiceContainer ( ) : System

Initializes a new SimpleServiceContainer.

SimpleServiceContainer ( IServiceProvider baseProvider ) : System

Initializes a new SimpleServiceContainer with a BaseProvider.

Защищенные методы

Метод Описание
Dispose ( bool disposing ) : void

When disposing is true, calls Clear to unregister all services. Any "on remove" actions are executed. Whether Dispose() has been called.

GetDirectService ( Type serviceType ) : object

Must return built-in services if any. These services take precedence over any registered services. This base implementation returns this object for IServiceProvider and ISimpleServiceContainer.

Приватные методы

Метод Описание
DoAdd ( Type s, ServiceEntry e ) : void

Correct ArgumentException throw by a Dictionary when adding an existing key.

Описание методов

Add() публичный Метод

Registers a service associated to a callback (and an optional callback that will be called when the service will be removed). The serviceInstance is called as long as no service has been obtained (serviceInstance returns null). Once the actual service has been obtained, it is kept and serviceInstance is not called anymore.
public Add ( Type serviceType, Func serviceInstance, Action onRemove ) : ISimpleServiceContainer
serviceType System.Type Service type to register. It must not already exist in this container otherwise an exception is thrown.
serviceInstance Func Delegate to call when needed. Can not be null.
onRemove Action Optional action that will be called whenever , or /// is called and a service as been successfully obtained.
Результат ISimpleServiceContainer

Add() публичный Метод

Registers a service with its implementation (and an optional callback that will be called when the service will be removed).
public Add ( Type serviceType, object serviceInstance, Action onRemove ) : ISimpleServiceContainer
serviceType System.Type Service type to register. It must not already exist in this container otherwise an exception is thrown.
serviceInstance object Implementation of the service. Can not be null.
onRemove Action Optional action that will be called whenever , or .
Результат ISimpleServiceContainer

AddDisabled() публичный Метод

Disables a service: null will always be returned by this IServiceProvider.GetService regardless of any fallbacks from BaseProvider. Direct services returned by GetDirectService can not be disabled.
This is not the same as calling Add(Type,Func{Object},Action{Object}) with a null instance. A null instance for a service (a callback that always returns null) is nearly the same as calling Remove: any fallbacks (to a base IServiceProvider for example) can occur. This is stronger since this must prevent fallbacks.
public AddDisabled ( Type serviceType ) : ISimpleServiceContainer
serviceType System.Type Service type to disable. It must not already exist in this container otherwise an exception is thrown.
Результат ISimpleServiceContainer

Clear() публичный Метод

Unregisters all the services. Any "on remove" actions are executed.
public Clear ( ) : ISimpleServiceContainer
Результат ISimpleServiceContainer

Dispose() публичный Метод

Disposing calls Clear to unregister all services. Any "on remove" actions are executed.
public Dispose ( ) : void
Результат void

Dispose() защищенный Метод

When disposing is true, calls Clear to unregister all services. Any "on remove" actions are executed. Whether Dispose() has been called.
protected Dispose ( bool disposing ) : void
disposing bool
Результат void

GetDirectService() защищенный Метод

Must return built-in services if any. These services take precedence over any registered services. This base implementation returns this object for IServiceProvider and ISimpleServiceContainer.
protected GetDirectService ( Type serviceType ) : object
serviceType System.Type Type of the service to obtain.
Результат object

GetService() публичный Метод

Implements IServiceProvider.GetService.
public GetService ( Type serviceType ) : object
serviceType System.Type Type of the service to obtain.
Результат object

Remove() публичный Метод

Unregisters a service. Can be called even if the service does not exist. The service is first removed and then the OnRemove associated action is called if it exists.
public Remove ( Type serviceType ) : ISimpleServiceContainer
serviceType System.Type Service type to unregister.
Результат ISimpleServiceContainer

SimpleServiceContainer() публичный Метод

Initializes a new SimpleServiceContainer.
public SimpleServiceContainer ( ) : System
Результат System

SimpleServiceContainer() публичный Метод

Initializes a new SimpleServiceContainer with a BaseProvider.
public SimpleServiceContainer ( IServiceProvider baseProvider ) : System
baseProvider IServiceProvider Base provider.
Результат System