public IRegistration Register <TContract, TService>(ComponentLifeCycles lifeCycles) where TService : class, TContract { Node node = new Node(_container, typeof(TContract), typeof(TService)); _kernel.CreateNode(node); return(this); }
public IRegistration Register <TContract, TService>(string key, ComponentLifeCycles lifeCycles = ComponentLifeCycles.Transient) where TService : class, TContract { Node node = new Node(_container, typeof(TContract), typeof(TService), key); node.ComponentLifeCycle = lifeCycles; _kernel.CreateNode(node); return(this); }
public IRegistration WithLifeCycle(ComponentLifeCycles lifeCycle) { var node = this._kernel.Nodes.LastOrDefault(); if (node == null) { throw new InvalidOperationException( "You must first specify a component registration via Register(...) before configuring the life cycle of the component in the container."); } node.ComponentLifeCycle = lifeCycle; return(this); }
public IRegistration Register(string key, Type contract, Type service, ComponentLifeCycles lifeCycles) { if (service == null) { throw new InvalidOperationException("The type denoting the concrete service type cannot be null"); } if (contract != null) { if (contract.IsInterface == false) { throw new InvalidOperationException(new StringBuilder() .AppendFormat("The contract '{0}' that is bound to service component '{1}' must be an interface type.", contract.Name, service.Name).ToString()); } if (contract.IsAssignableFrom(service) == false) { throw new InvalidOperationException(new StringBuilder() .AppendFormat("The service '{0}' does not implement the contract '{1}'.", service.Name, contract.Name).ToString()); } } Node node = null; if (contract != null) { node = new Node(_container, contract, service, key); } else { node = new Node(_container, service, key); } _kernel.CreateNode(node); return(this); }