CK.Core.SimpleServiceContainer.Add C# (CSharp) Method

Add() public method

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.
return ISimpleServiceContainer
        public ISimpleServiceContainer Add( Type serviceType, Func<Object> serviceInstance, Action<Object> onRemove )
        {
            if( ReferenceEquals( serviceType, null ) ) throw new ArgumentNullException( "serviceType" );
            if( serviceInstance == null ) throw new ArgumentNullException( "serviceInstance" );
            if( GetDirectService( serviceType ) != null ) throw new CKException( CoreResources.ServiceAlreadyDirectlySupported, serviceType.FullName );
            DoAdd( serviceType, new ServiceEntry() { Instance = null, Creator = serviceInstance, OnRemove = onRemove } );
            return this;
        }

Same methods

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

Usage Example

Example #1
0
        MiniContext( string name )
        {
            ServiceContainer = new SimpleServiceContainer();
            ServiceContainer.Add( RequirementLayerSerializer.Instance );
            ServiceContainer.Add( SimpleTypeFinder.Default );

            ConfigContainer = SharedDictionary.Create( ServiceContainer );
            ConfigManager = ConfigurationManager.Create( ConfigContainer ).ConfigManager;

        }
All Usage Examples Of CK.Core.SimpleServiceContainer::Add