示例#1
0
        public static void Initialize(IServiceProvider serviceProvider, object providerPropertyKey)
        {
            serviceProvider.AssertNotNull(nameof(serviceProvider));
            providerPropertyKey.AssertNotNull(nameof(providerPropertyKey));

            AppProperty.Set(providerPropertyKey, serviceProvider);
            _providerPropertyKey = providerPropertyKey;
        }
示例#2
0
        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();
        }