protected override void OnRegisterTransientMethod(IDependencyMethodInfo info) { foreach (var resolveType in info.ResolvedTypes) { _services.AddTransient(resolveType, p => info.Execute(info.CreateContext(Ioc.Container))); } base.OnRegisterTransientMethod(info); }
private static object ExecuteMethod(IDependencyMethodInfo info, IContext ctx) { var context = info.CreateContext(Ioc.Container); if (ctx.Parameters.Count == 0) { return(info.Execute(context)); } var args = ctx.Parameters.Select(s => ValueTuple.Create(s.Name, s.GetValue(ctx, ctx.Request.Target))).ToArray(); return(info.Execute(context.SetArguments(args))); }
private bool TryRegisterMethod(IDependencyMethodInfo info) { if (info == null) { return(false); } switch (info.Scope) { case DependyBuilderScope.Transient: OnRegisterTransientMethod(info); break; case DependyBuilderScope.Singleton: OnRegisterSingletonMethod(info); break; default: throw new NotSupportedException($"{info.Scope} scope not currently supported for {info}."); } return(true); }
/// <summary> /// Register a transient <see cref="IDependencyMethodInfo"/> instance with the /// configuration. Can be overridden. /// </summary> /// <param name="info">The dependency information describing the resolving requirements.</param> protected virtual void OnRegisterTransientMethod(IDependencyMethodInfo info) { _configuration.Add(info.ResolvedTypes, new DependencyMethodResolution(info)); }
/// <summary> /// Register a singleton <see cref="IDependencyMethodInfo"/> instance with the /// configuration. Can be overridden. /// </summary> /// <param name="info">The dependency information describing the resolving requirements.</param> protected virtual void OnRegisterSingletonMethod(IDependencyMethodInfo info) { _configuration.Add(info.ResolvedTypes, new DependencySingletionResolution <IDependencyMethodInfo, DependencyMethodResolution>(new DependencyMethodResolution(info))); }