Ejemplo n.º 1
0
        private static object ResolveByActivator(RepositoryType repositoryItem, bool canCache)
        {
            if (!repositoryItem.UseActicator)
            {
                repositoryItem.CountCacheInstance++;
                return(repositoryItem.Instance);
            }

            if (!canCache)
            {
                repositoryItem.CountNewInstance++;
                return(Activator.CreateInstance(repositoryItem.ConcretType));
            }

            if (repositoryItem.Instance == null)
            {
                repositoryItem.CountNewInstance++;

                repositoryItem.Instance = Activator.CreateInstance(repositoryItem.ConcretType, repositoryItem.ConstructorParams);
                return(repositoryItem.Instance);
            }

            repositoryItem.CountCacheInstance++;

            return(repositoryItem.Instance);
        }
Ejemplo n.º 2
0
 internal static void Map(Type contract, Type concret, object instance, object[] constructorParams, Func <object> resolver)
 {
     lock (Repository)
     {
         Repository[contract] = new RepositoryType
         {
             Instance          = instance,
             ConstructorParams = constructorParams,
             Resolver          = resolver,
             ConcretType       = concret,
             UseResolver       = resolver != null,
             UseActicator      = instance == null
         };
     }
 }
Ejemplo n.º 3
0
        private static object ResolveByFunction(RepositoryType repositoryItem, bool canCache)
        {
            if (!canCache)
            {
                repositoryItem.CountNewInstance++;
                return(repositoryItem.Resolver());
            }

            if (repositoryItem.Instance == null)
            {
                repositoryItem.CountNewInstance++;
                repositoryItem.Instance = repositoryItem.Resolver();

                return(repositoryItem.Instance);
            }

            repositoryItem.CountCacheInstance++;
            return(repositoryItem.Instance);
        }