public static void Initialize(IServiceProvider serviceProvider, object providerPropertyKey) { serviceProvider.AssertNotNull(nameof(serviceProvider)); providerPropertyKey.AssertNotNull(nameof(providerPropertyKey)); AppProperty.Set(providerPropertyKey, serviceProvider); _providerPropertyKey = providerPropertyKey; }
public static object Resolve(Type valueType) { var provider = AppProperty.Get <IServiceProvider>(_providerPropertyKey); var value = provider.GetService(valueType); if (valueType.IsAssignableFrom(value.GetType())) { return(value); } throw new InvalidCastException(); }