/// <summary> /// Registers the specified object with its related lifetime manager, and the /// construction parameters used by the lifetime manager. /// </summary> /// <param name="serviceType">Type of service to register</param> /// <param name="serviceObjectType">Type of object implementing the service</param> /// <param name="parameters">Object construction parameters</param> /// <param name="properties">Object properties to inject</param> /// <param name="ltManager">Lifetime manager object</param> /// <param name="customContext"></param> public void Register(Type serviceType, Type serviceObjectType, InjectedParameterSettingsCollection parameters = null, PropertySettingsCollection properties = null, ILifetimeManager ltManager = null, object customContext = null) { if (serviceType == null) { throw new ArgumentNullException("serviceType"); } if (serviceObjectType == null) { throw new ArgumentNullException("serviceObjectType"); } if (_services.ContainsKey(serviceType)) { throw new ServiceAlreadyRegisteredException(serviceType); } // --- Register the new mapping _services[serviceType] = new ServiceMapping( serviceType, serviceObjectType, ltManager ?? new PerCallLifetimeManager(), parameters, properties, customContext); // --- Reset lifetime managers foreach (var mapping in _services.Values) { mapping.LifetimeManager.ResetState(); mapping.Resolved = false; } }
/// <summary> /// Registers the specified object with its related lifetime manager, and the /// construction parameters used by the lifetime manager. /// </summary> /// <typeparam name="TService">Type of service to register</typeparam> /// <typeparam name="TObject">Type of object implementing the service</typeparam> /// <param name="parameters">Object construction parameters</param> /// <param name="properties">Object properties to inject</param> /// <param name="ltManager">Lifetime manager object</param> /// <param name="customContext"></param> public static void Register <TService, TObject>(InjectedParameterSettingsCollection parameters = null, PropertySettingsCollection properties = null, ILifetimeManager ltManager = null, object customContext = null) { ServiceRegistry.DefaultContainer.Register(typeof(TService), typeof(TObject), parameters, properties, ltManager, customContext); }
/// <summary> /// Registers the specified object with its related lifetime manager, and the /// construction parameters used by the lifetime manager. /// </summary> /// <param name="serviceType">Type of service to register</param> /// <param name="serviceObjectType">Type of object implementing the service</param> /// <param name="parameters">Object construction parameters</param> /// <param name="properties">Object properties to inject</param> /// <param name="ltManager">Lifetime manager object</param> /// <param name="customContext"></param> public static void Register(Type serviceType, Type serviceObjectType, InjectedParameterSettingsCollection parameters = null, PropertySettingsCollection properties = null, ILifetimeManager ltManager = null, object customContext = null) { ServiceRegistry.DefaultContainer.Register(serviceType, serviceObjectType, parameters, properties, ltManager, customContext); }
/// <summary> /// Parse the specified configuration settings /// </summary> /// <param name="element">Element holding configuration settings</param> protected override void ParseFromXml(XElement element) { From = element.TypeAttribute(FROM, _typeResolver); To = element.TypeAttribute(TO, _typeResolver); Lifetime = element.OptionalTypeAttribute(LIFETIME, new LifeTimeTypeResolver(_typeResolver)); element.ProcessOptionalElement(PROPERTIES, item => Properties = new PropertySettingsCollection(item)); element.ProcessOptionalElement(CONSTRUCT, item => Parameters = new InjectedParameterSettingsCollection(item, _typeResolver)); }
public MappingSettings(Type @from, Type to, Type lifetime = null, InjectedParameterSettingsCollection parameters = null, PropertySettingsCollection properties = null) { From = @from; To = to; Lifetime = lifetime; Parameters = parameters; Properties = properties; }
/// <summary> /// Creates a new instance with the specified parameters. /// </summary> public ServiceMapping( Type serviceType, Type serviceObjectType, ILifetimeManager lifetimeManager, InjectedParameterSettingsCollection constructionParameters, PropertySettingsCollection properties, object customContext) { ServiceType = serviceType; ServiceObjectType = serviceObjectType; LifetimeManager = lifetimeManager; ConstructionParameters = constructionParameters; Properties = properties; CustomContext = customContext; }