public object Resolve(IDependencyTypeInfo info, params object[] args)
        {
            if (args == null || args.Length == 0)
            {
                return(Resolve(info));
            }

            return(ActivatorUtilities.CreateInstance(ServiceProvider, info.ResolutionType, args));
        }
Ejemplo n.º 2
0
        protected override void OnRegisterTransient(IDependencyTypeInfo info)
        {
            foreach (var resolveType in info.ResolvedTypes)
            {
                _services.AddTransient(resolveType, info.ResolutionType);
            }

            base.OnRegisterTransient(info);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Convert a generic type info into a concrete type info
        /// </summary>
        /// <param name="typeInfo">The current dependency info</param>
        /// <param name="genericTypeArguments">The generic type arguments.</param>
        /// <returns>A new instance of the dependency info with the concrete information set.</returns>
        public static IDependencyTypeInfo As(this IDependencyTypeInfo typeInfo, params Type[] genericTypeArguments)
        {
            if (!typeInfo.ResolutionType.IsGenericType)
            {
                throw new InvalidOperationException($"The info resolved type for '{typeInfo}' is not a generic type.");
            }

            var resovleType = typeInfo.ResolutionType;

            return(As(typeInfo, genericTypeArguments, resovleType, rt => new DependencyTypeInfo(rt, typeInfo)));
        }
Ejemplo n.º 4
0
        private bool TryRegisterTypeTo(IDependencyTypeInfo info)
        {
            if (info == null)
            {
                return(false);
            }

            switch (info.Scope)
            {
            case DependyBuilderScope.Transient:
                OnRegisterTransient(info);
                break;

            case DependyBuilderScope.Singleton:
                OnRegisterSingleton(info);
                break;

            default:
                throw new NotSupportedException($"{info.Scope} scope not currently supported for {info}.");
            }

            return(true);
        }
Ejemplo n.º 5
0
 public object Resolve(IDependencyTypeInfo info, params (string, object)[] args)
Ejemplo n.º 6
0
 public object Resolve(IDependencyTypeInfo info, params object[] args)
 {
     return(_creation.New(info.ResolutionType, args));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Register a singleton <see cref="IDependencyTypeInfo"/> instance with the configuration.
 /// Can be overridden.
 /// </summary>
 /// <param name="info">The dependency information describing the resolving requirements.</param>
 protected virtual void OnRegisterSingleton(IDependencyTypeInfo info)
 {
     _configuration.Add(info.ResolvedTypes, new DependencySingletionResolution <IDependencyTypeInfo, DependencyTypeResolution>(new DependencyTypeResolution(info, _activator)));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Register a transient <see cref="IDependencyTypeInfo"/> instance with the configuration.
 /// Can be overridden.
 /// </summary>
 /// <param name="info">The dependency information describing the resolving requirements.</param>
 protected virtual void OnRegisterTransient(IDependencyTypeInfo info)
 {
     _configuration.Add(info.ResolvedTypes, new DependencyTypeResolution(info, _activator));
 }