private object ResolveNewInstance(ContainerKey registerKey) { object instance = Instanciate(registerKey); var implementation = LazyImplementations[registerKey].ImplementationType; SetInjectedFields(instance, implementation); SetInjectedProperties(instance, implementation); return(instance); }
private object Resolve(InjectionType injectionType, ContainerKey key) { switch (injectionType) { case InjectionType.Singleton: return(Resolve(key)); case InjectionType.NewInstance: return(ResolveNewInstance(key)); default: throw new ArgumentException(); } }
private object Instanciate(ContainerKey registerKey) { try { var implementation = LazyImplementations[registerKey].ImplementationType; return(Instanciate(implementation)); } catch (KeyNotFoundException ex) { throw new IocException($"the key: {registerKey.InterfaceType.Name}(\"{registerKey.Name}\") does not exist in container.", ex); } }
private object Resolve(ContainerKey registerKey) => LazyImplementations[registerKey].LazyInstance.Value;
public void RegisterInstance <Interface>(Interface implementation, ContainerKey registerKey) { LazyImplementations[registerKey] = (implementation.GetType(), new Lazy <object>(() => implementation)); }
private void ReplaceByNewInstance <T>(ContainerKey registerKey) { RegisterInstance((T)ResolveNewInstance(registerKey), registerKey); }