示例#1
0
文件: Di.cs 项目: Delt06/di-framework
        /// <summary>
        /// Inject dependencies into components of the provided Game Object (from the specified sources).
        /// </summary>
        /// <param name="gameObject">Injected Game Object.</param>
        /// <param name="sources">Sources to get dependencies from.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="gameObject"/> is null.</exception>
        public static void Inject([NotNull] GameObject gameObject, DependencySource sources)
        {
            if (gameObject == null)
            {
                throw new ArgumentNullException(nameof(gameObject));
            }

            var resolver = ResolverPool.Rent(gameObject, sources);

            try
            {
                resolver.Resolve();
            }
            finally
            {
                ResolverPool.Return(resolver);
            }
        }
示例#2
0
 private CachedComponentResolver RentResolver() => ResolverPool.Rent(gameObject, _dependencySource);