本文整理汇总了C#中JobHostConfiguration.AddService方法的典型用法代码示例。如果您正苦于以下问题:C# JobHostConfiguration.AddService方法的具体用法?C# JobHostConfiguration.AddService怎么用?C# JobHostConfiguration.AddService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JobHostConfiguration
的用法示例。
在下文中一共展示了JobHostConfiguration.AddService方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize_PerformsExpectedRegistrations
public void Initialize_PerformsExpectedRegistrations()
{
JobHostConfiguration config = new JobHostConfiguration();
config.AddService<INameResolver>(new RandomNameResolver());
ServiceBusConfiguration serviceBusConfig = new ServiceBusConfiguration();
ServiceBusExtensionConfig serviceBusExtensionConfig = new ServiceBusExtensionConfig(serviceBusConfig);
IExtensionRegistry extensions = config.GetService<IExtensionRegistry>();
ITriggerBindingProvider[] triggerBindingProviders = extensions.GetExtensions<ITriggerBindingProvider>().ToArray();
Assert.Equal(0, triggerBindingProviders.Length);
IBindingProvider[] bindingProviders = extensions.GetExtensions<IBindingProvider>().ToArray();
Assert.Equal(0, bindingProviders.Length);
ExtensionConfigContext context = new ExtensionConfigContext
{
Config = config,
Trace = new TestTraceWriter(TraceLevel.Verbose)
};
serviceBusExtensionConfig.Initialize(context);
// ensure the ServiceBusTriggerAttributeBindingProvider was registered
triggerBindingProviders = extensions.GetExtensions<ITriggerBindingProvider>().ToArray();
Assert.Equal(1, triggerBindingProviders.Length);
ServiceBusTriggerAttributeBindingProvider triggerBindingProvider = (ServiceBusTriggerAttributeBindingProvider)triggerBindingProviders[0];
Assert.NotNull(triggerBindingProvider);
// ensure the ServiceBusAttributeBindingProvider was registered
bindingProviders = extensions.GetExtensions<IBindingProvider>().ToArray();
Assert.Equal(1, bindingProviders.Length);
ServiceBusAttributeBindingProvider bindingProvider = (ServiceBusAttributeBindingProvider)bindingProviders[0];
Assert.NotNull(bindingProvider);
}
示例2: CreateAndLogHostStartedAsync
public static async Task<JobHostContext> CreateAndLogHostStartedAsync(
JobHost host,
IStorageAccountProvider storageAccountProvider,
IQueueConfiguration queueConfiguration,
ITypeLocator typeLocator,
IJobActivator activator,
INameResolver nameResolver,
IConsoleProvider consoleProvider,
JobHostConfiguration config,
CancellationToken shutdownToken,
CancellationToken cancellationToken,
IHostIdProvider hostIdProvider = null,
FunctionExecutor functionExecutor = null,
IFunctionIndexProvider functionIndexProvider = null,
IBindingProvider bindingProvider = null,
IHostInstanceLoggerProvider hostInstanceLogerProvider = null,
IFunctionInstanceLoggerProvider functionInstanceLoggerProvider = null,
IFunctionOutputLoggerProvider functionOutputLoggerProvider = null,
IBackgroundExceptionDispatcher backgroundExceptionDispatcher = null,
SingletonManager singletonManager = null)
{
if (hostIdProvider == null)
{
hostIdProvider = new DynamicHostIdProvider(storageAccountProvider, () => functionIndexProvider);
}
IExtensionTypeLocator extensionTypeLocator = new ExtensionTypeLocator(typeLocator);
if (backgroundExceptionDispatcher == null)
{
backgroundExceptionDispatcher = BackgroundExceptionDispatcher.Instance;
}
ContextAccessor<IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor = new ContextAccessor<IMessageEnqueuedWatcher>();
ContextAccessor<IBlobWrittenWatcher> blobWrittenWatcherAccessor = new ContextAccessor<IBlobWrittenWatcher>();
ISharedContextProvider sharedContextProvider = new SharedContextProvider();
// Create a wrapper TraceWriter that delegates to both the user
// TraceWriter specified on Config (if present), as well as to Console
TraceWriter trace = new ConsoleTraceWriter(config.Tracing, consoleProvider.Out);
// Register system services with the service container
config.AddService<INameResolver>(nameResolver);
ExtensionConfigContext context = new ExtensionConfigContext
{
Config = config,
Trace = trace,
Host = host
};
InvokeExtensionConfigProviders(context);
IExtensionRegistry extensions = config.GetExtensions();
ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver,
storageAccountProvider, extensionTypeLocator, hostIdProvider, queueConfiguration, backgroundExceptionDispatcher,
messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, sharedContextProvider, extensions, trace);
if (bindingProvider == null)
{
bindingProvider = DefaultBindingProvider.Create(nameResolver, storageAccountProvider, extensionTypeLocator, messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, extensions);
}
DefaultLoggerProvider loggerProvider = new DefaultLoggerProvider(storageAccountProvider, trace);
if (singletonManager == null)
{
singletonManager = new SingletonManager(storageAccountProvider, backgroundExceptionDispatcher, config.Singleton, trace, config.NameResolver);
}
using (CancellationTokenSource combinedCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, shutdownToken))
{
CancellationToken combinedCancellationToken = combinedCancellationSource.Token;
await WriteSiteExtensionManifestAsync(combinedCancellationToken);
IStorageAccount dashboardAccount = await storageAccountProvider.GetDashboardAccountAsync(combinedCancellationToken);
IHostInstanceLogger hostInstanceLogger = null;
if (hostInstanceLogerProvider != null)
{
hostInstanceLogger = await hostInstanceLogerProvider.GetAsync(combinedCancellationToken);
}
else
{
hostInstanceLogger = await((IHostInstanceLoggerProvider)loggerProvider).GetAsync(combinedCancellationToken);
}
IFunctionInstanceLogger functionInstanceLogger = null;
if (functionInstanceLoggerProvider != null)
{
functionInstanceLogger = await functionInstanceLoggerProvider.GetAsync(combinedCancellationToken);
}
else
{
functionInstanceLogger = (IFunctionInstanceLogger)(await((IFunctionInstanceLoggerProvider)loggerProvider).GetAsync(combinedCancellationToken));
}
IFunctionOutputLogger functionOutputLogger = null;
if (functionOutputLoggerProvider != null)
{
functionOutputLogger = await functionOutputLoggerProvider.GetAsync(combinedCancellationToken);
}
//.........这里部分代码省略.........
示例3: AddService_ThrowsArgumentOutOfRange_WhenInstanceNotInstanceOfType
public void AddService_ThrowsArgumentOutOfRange_WhenInstanceNotInstanceOfType()
{
JobHostConfiguration configuration = new JobHostConfiguration();
ArgumentOutOfRangeException exception = Assert.Throws<ArgumentOutOfRangeException>(
() => configuration.AddService(typeof(IComparable), new object())
);
Assert.Equal("serviceInstance", exception.ParamName);
}
示例4: AddService_ThrowsArgumentNull_WhenServiceTypeIsNull
public void AddService_ThrowsArgumentNull_WhenServiceTypeIsNull()
{
JobHostConfiguration configuration = new JobHostConfiguration();
ArgumentNullException exception = Assert.Throws<ArgumentNullException>(
() => configuration.AddService(null, "test1")
);
Assert.Equal("serviceType", exception.ParamName);
}
示例5: AddService_ReplacesExistingService
public void AddService_ReplacesExistingService()
{
JobHostConfiguration configuration = new JobHostConfiguration();
IComparable service = "test1";
configuration.AddService<IComparable>(service);
IComparable result = configuration.GetService<IComparable>();
Assert.Same(service, result);
IComparable service2 = "test2";
configuration.AddService<IComparable>(service2);
result = configuration.GetService<IComparable>();
Assert.Same(service2, result);
}
示例6: AddService_AddsNewService
public void AddService_AddsNewService()
{
JobHostConfiguration configuration = new JobHostConfiguration();
IComparable service = "test1";
configuration.AddService<IComparable>(service);
IComparable result = configuration.GetService<IComparable>();
Assert.Same(service, result);
}
示例7: OnInitializeConfig
protected override void OnInitializeConfig(JobHostConfiguration config)
{
base.OnInitializeConfig(config);
// Add our WebHost specific services
config.AddService<IMetricsLogger>(_metricsLogger);
}