public object GetService(Type serviceType, string name, object constructorArgsAsAnonymousType = null) { name = name ?? string.Empty; var args = ConstructorArgsHelper.GetConstructorArgs(serviceType, name, constructorArgsAsAnonymousType); if (args == null) { return(ServiceFactory.GetInstance(serviceType, name)); } return(ServiceFactory.GetInstance(serviceType, name, args)); }
public void RegisterType(Type serviceType, Type implementationType, string name, LifetimeType lifetime, object constructorArgsAsAnonymousType = null) { Ensure.NotNull(serviceType, nameof(serviceType)); Ensure.NotNull(implementationType, nameof(implementationType)); name = name ?? string.Empty; if (constructorArgsAsAnonymousType == null) { _container.Register(serviceType, implementationType, name, GetLifetime(lifetime)); } else { _container.Register(new ServiceRegistration { ServiceType = serviceType, FactoryExpression = ConstructorArgsHelper.GetFactoryDelegate(serviceType, implementationType, name, constructorArgsAsAnonymousType), ServiceName = name, Lifetime = GetLifetime(lifetime) }); } }