public void AddToDefaultFactories(TFactory factory) { Type type = factory.Type; if (type == null) { throw new ArgumentException("Registered type is null !"); } if (_defaultFactories.TryGetValue(type, out OriginFactories <TFactory> originFactories)) { if (factory.InstanceOrigin != null) { TFactory originFactory = originFactories[factory.InstanceOrigin.Value]; if (originFactory.InstanceOrigin != null && originFactory.Substitution == Substitution.Forbidden) { throw new AlreadyRegisterException(type); } } } else { originFactories = new OriginFactories <TFactory>(); _defaultFactories[type] = originFactories; } originFactories[factory.InstanceOrigin] = factory; }
public void AddToKeyedFactories(TFactory factory) { Type type = factory.Type; object serviceKey = factory.Key; OriginFactories <TFactory> originFactories; if (_keyedFactories.TryGetValue(serviceKey, out Dictionary <Type, OriginFactories <TFactory> > factoryDictionary)) { if (factoryDictionary.TryGetValue(type, out originFactories)) { if (factory.InstanceOrigin != null) { TFactory originFactory = originFactories[factory.InstanceOrigin.Value]; if (originFactory.InstanceOrigin != null && originFactory.Substitution == Substitution.Forbidden) { throw new AlreadyRegisterException(serviceKey); } } } else { originFactories = new OriginFactories <TFactory>(); factoryDictionary[type] = originFactories; } } else { factoryDictionary = new Dictionary <Type, OriginFactories <TFactory> >(); _keyedFactories.Add(serviceKey, factoryDictionary); originFactories = new OriginFactories <TFactory>(); factoryDictionary[type] = originFactories; } originFactories[factory.InstanceOrigin] = factory; }