Exemplo n.º 1
0
        private object ResolveNewInstance(ContainerKey registerKey)
        {
            object instance       = Instanciate(registerKey);
            var    implementation = LazyImplementations[registerKey].ImplementationType;

            SetInjectedFields(instance, implementation);
            SetInjectedProperties(instance, implementation);
            return(instance);
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
 private object Resolve(ContainerKey registerKey) => LazyImplementations[registerKey].LazyInstance.Value;
Exemplo n.º 5
0
 public void RegisterInstance <Interface>(Interface implementation, ContainerKey registerKey)
 {
     LazyImplementations[registerKey] = (implementation.GetType(), new Lazy <object>(() => implementation));
 }
Exemplo n.º 6
0
 private void ReplaceByNewInstance <T>(ContainerKey registerKey)
 {
     RegisterInstance((T)ResolveNewInstance(registerKey), registerKey);
 }