Created
October 9, 2019 01:29
-
-
Save xcap2000/2d264960cae55cf131edaa907a1a3eae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using Unity; | |
using Unity.Resolution; | |
namespace MlWebUi.Common.Resolvers | |
{ | |
public class Resolver<T> : IResolver<T> | |
{ | |
private readonly IUnityContainer container; | |
private readonly string? name; | |
public Resolver(IUnityContainer container, string? name = null) | |
{ | |
this.container = container; | |
this.name = name; | |
} | |
public T Resolve() | |
{ | |
return container.Resolve<T>(name); | |
} | |
public T Resolve(params object[] arguments) | |
{ | |
var overrides = new List<ResolverOverride>(); | |
foreach (var argument in arguments) | |
{ | |
overrides.Add(Override.Parameter(argument.GetType(), argument)); | |
} | |
return container.Resolve<T>(name, overrides.ToArray()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment