本文整理汇总了C#中IServiceProvider.?.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceProvider.?.GetService方法的具体用法?C# IServiceProvider.?.GetService怎么用?C# IServiceProvider.?.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceProvider
的用法示例。
在下文中一共展示了IServiceProvider.?.GetService方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: KeyRingProvider
public KeyRingProvider(IKeyManager keyManager, KeyManagementOptions keyManagementOptions, IServiceProvider services)
{
_keyManagementOptions = new KeyManagementOptions(keyManagementOptions); // clone so new instance is immutable
_keyManager = keyManager;
_cacheableKeyRingProvider = services?.GetService<ICacheableKeyRingProvider>() ?? this;
_logger = services?.GetLogger<KeyRingProvider>();
_defaultKeyResolver = services?.GetService<IDefaultKeyResolver>()
?? new DefaultKeyResolver(_keyManagementOptions.KeyPropagationWindow, _keyManagementOptions.MaxServerClockSkew, services);
}
示例2: GetCheckpointerSettings
public ICheckpointerSettings GetCheckpointerSettings(IProviderConfiguration providerConfig, IServiceProvider serviceProvider)
{
// if no checkpointer settings type is provided, use EventHubCheckpointerSettings and get populate settings from providerConfig
if (CheckpointerSettingsType == null)
{
CheckpointerSettingsType = typeof(EventHubCheckpointerSettings);
}
var checkpointerSettings = (ICheckpointerSettings)(serviceProvider?.GetService(CheckpointerSettingsType) ?? Activator.CreateInstance(CheckpointerSettingsType));
if (checkpointerSettings == null)
{
throw new ArgumentOutOfRangeException(nameof(providerConfig), "CheckpointerSettingsType not valid.");
}
// if settings is an EventHubCheckpointerSettings class, populate settings from providerConfig
var settings = checkpointerSettings as EventHubCheckpointerSettings;
if (settings != null)
{
settings.PopulateFromProviderConfig(providerConfig);
}
return checkpointerSettings;
}
示例3: EncryptedXmlDecryptor
/// <summary>
/// Creates a new instance of an <see cref="EncryptedXmlDecryptor"/>.
/// </summary>
/// <param name="services">An optional <see cref="IServiceProvider"/> to provide ancillary services.</param>
public EncryptedXmlDecryptor(IServiceProvider services)
{
_decryptor = services?.GetService<IInternalEncryptedXmlDecryptor>() ?? this;
}
示例4: CertificateXmlEncryptor
internal CertificateXmlEncryptor(IServiceProvider services)
{
_encryptor = services?.GetService<IInternalCertificateXmlEncryptor>() ?? this;
_logger = services.GetLogger<CertificateXmlEncryptor>();
}
示例5: GetEventHubSettings
/// <summary>
/// Aquire configured IEventHubSettings class
/// </summary>
/// <param name="providerConfig"></param>
/// <param name="serviceProvider"></param>
/// <returns></returns>
public IEventHubSettings GetEventHubSettings(IProviderConfiguration providerConfig, IServiceProvider serviceProvider)
{
// if no event hub settings type is provided, use EventHubSettings and get populate settings from providerConfig
if (EventHubSettingsType == null)
{
EventHubSettingsType = typeof(EventHubSettings);
}
var hubSettings = (IEventHubSettings)(serviceProvider?.GetService(EventHubSettingsType) ?? Activator.CreateInstance(EventHubSettingsType));
if (hubSettings == null)
{
throw new ArgumentOutOfRangeException(nameof(providerConfig), "EventHubSettingsType not valid.");
}
// if settings is an EventHubSettings class, populate settings from providerConfig
var settings = hubSettings as EventHubSettings;
settings?.PopulateFromProviderConfig(providerConfig);
return hubSettings;
}
示例6: GetUIThread
private static UIThreadBase GetUIThread(IServiceProvider provider) {
var uiThread = (UIThreadBase)provider?.GetService(typeof(UIThreadBase));
return uiThread ?? new NoOpUIThread();
}
示例7: OpenAt
internal static void OpenAt(IServiceProvider site, IPythonInterpreterFactory interpreter, Type extension = null) {
var wnd = (site?.GetService(typeof(IPythonToolsToolWindowService)) as IPythonToolsToolWindowService)
?.GetWindowPane(typeof(InterpreterListToolWindow), true) as InterpreterListToolWindow;
var envs = wnd?.Content as ToolWindow;
if (envs == null) {
Debug.Fail("Failed to get environment list window");
return;
}
ErrorHandler.ThrowOnFailure((wnd.Frame as IVsWindowFrame)?.Show() ?? 0);
if (extension == null) {
SelectEnv(envs, interpreter, 3);
} else {
SelectEnvAndExt(envs, interpreter, extension, 3);
}
}
示例8: CreateInstance
/// <summary>
/// This method will search internal tables within TypeDescriptor for
/// a TypeDescriptionProvider object that is associated with the given
/// data type. If it finds one, it will delegate the call to that object.
/// </summary>
public static object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args)
{
if (objectType == null)
{
throw new ArgumentNullException(nameof(objectType));
}
if (argTypes != null)
{
if (args == null)
{
throw new ArgumentNullException(nameof(args));
}
if (argTypes.Length != args.Length)
{
throw new ArgumentException(SR.TypeDescriptorArgsCountMismatch);
}
}
object instance = null;
// See if the provider wants to offer a TypeDescriptionProvider to delegate to. This allows
// a caller to have complete control over all object instantiation.
TypeDescriptionProvider p = provider?.GetService(typeof(TypeDescriptionProvider)) as TypeDescriptionProvider;
if (p != null)
{
instance = p.CreateInstance(provider, objectType, argTypes, args);
}
return instance ?? NodeFor(objectType).CreateInstance(provider, objectType, argTypes, args);
}