Refactoring builder APIs, introducing IWebJobsBuilder, moving extensions

This commit is contained in:
Fabio Cavalcante 2018-08-06 19:54:08 -07:00
Родитель d655510dc6
Коммит 7b19acdfa6
71 изменённых файлов: 800 добавлений и 584 удалений

Просмотреть файл

@ -14,11 +14,14 @@ namespace SampleHost
{
var builder = new HostBuilder()
.UseEnvironment("Development")
.AddWebJobsLogging() // Enables WebJobs v1 classic logging
.AddAzureStorageCoreServices()
.AddAzureStorage()
.AddServiceBus()
.AddEventHubs()
.ConfigureWebJobs(b =>
{
b.AddWebJobsLogging() // Enables WebJobs v1 classic logging
.AddAzureStorageCoreServices()
.AddAzureStorage()
.AddServiceBus()
.AddEventHubs();
})
.AddApplicationInsights()
.ConfigureAppConfiguration(b =>
{

Просмотреть файл

@ -1,22 +1,21 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.EventHubs;
using Microsoft.Azure.WebJobs.ServiceBus;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.Extensions.Hosting
{
public static class EventHubHostBuilderExtensions
public static class EventHubWebJobsBuilderExtensions
{
public static IHostBuilder AddEventHubs(this IHostBuilder hostBuilder)
public static IWebJobsBuilder AddEventHubs(this IWebJobsBuilder builder)
{
return hostBuilder
.AddExtension<EventHubExtensionConfigProvider>()
.ConfigureServices(services =>
{
services.TryAddSingleton<EventHubConfiguration>();
});
builder.AddExtension<EventHubExtensionConfigProvider>();
builder.Services.TryAddSingleton<EventHubConfiguration>();
return builder;
}
}
}

Просмотреть файл

@ -11,7 +11,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.EventHubs
{
public class EventHubsWebJobsStartup : IWebJobsStartup
{
public void Configure(IHostBuilder builder)
public void Configure(IWebJobsBuilder builder)
{
builder.AddEventHubs();
}

Просмотреть файл

@ -23,9 +23,7 @@ namespace Microsoft.Extensions.Hosting
{
public static class StorageHostBuilderExtensions
{
// $$$ Extensions need some way to register services! Callable from Script (so not via an explicit Extension method)
public static IHostBuilder AddAzureStorage(this IHostBuilder builder)
public static IWebJobsBuilder AddAzureStorage(this IWebJobsBuilder builder)
{
// add webjobs to user agent for all storage calls
OperationContext.GlobalSendingRequest += (sender, e) =>
@ -33,38 +31,32 @@ namespace Microsoft.Extensions.Hosting
// TODO: FACAVAL - This is not supported on by the latest version of the
// storage SDK. Need to re-add this when the capability is reintroduced.
// e.UserAgent += " AzureWebJobs";
};
};
return builder
.ConfigureServices((context, services) =>
{
// $$$ Move to Host.Storage?
services.TryAddSingleton<ILoadbalancerQueue, StorageLoadbalancerQueue>();
// $$$ Move to Host.Storage?
builder.Services.TryAddSingleton<ILoadbalancerQueue, StorageLoadbalancerQueue>();
services.TryAddSingleton<SharedQueueWatcher>();
builder.Services.TryAddSingleton<SharedQueueWatcher>();
// $$$ Remove this, should be done via DI
services.TryAddSingleton<ISharedContextProvider, SharedContextProvider>();
// $$$ Remove this, should be done via DI
builder.Services.TryAddSingleton<ISharedContextProvider, SharedContextProvider>();
services.TryAddSingleton<StorageAccountProvider>();
builder.Services.TryAddSingleton<StorageAccountProvider>();
services.TryAddSingleton<IContextSetter<IBlobWrittenWatcher>>((p) => new ContextAccessor<IBlobWrittenWatcher>());
services.TryAddSingleton((p) => p.GetService<IContextSetter<IBlobWrittenWatcher>>() as IContextGetter<IBlobWrittenWatcher>);
builder.Services.TryAddSingleton<IContextSetter<IBlobWrittenWatcher>>((p) => new ContextAccessor<IBlobWrittenWatcher>());
builder.Services.TryAddSingleton((p) => p.GetService<IContextSetter<IBlobWrittenWatcher>>() as IContextGetter<IBlobWrittenWatcher>);
services.TryAddSingleton<IContextSetter<IMessageEnqueuedWatcher>>((p) => new ContextAccessor<IMessageEnqueuedWatcher>());
services.TryAddSingleton((p) => p.GetService<IContextSetter<IMessageEnqueuedWatcher>>() as IContextGetter<IMessageEnqueuedWatcher>);
builder.Services.TryAddSingleton<IContextSetter<IMessageEnqueuedWatcher>>((p) => new ContextAccessor<IMessageEnqueuedWatcher>());
builder.Services.TryAddSingleton((p) => p.GetService<IContextSetter<IMessageEnqueuedWatcher>>() as IContextGetter<IMessageEnqueuedWatcher>);
services.TryAddSingleton<BlobTriggerAttributeBindingProvider>();
builder.Services.TryAddSingleton<BlobTriggerAttributeBindingProvider>();
services.TryAddSingleton<QueueTriggerAttributeBindingProvider>();
builder.Services.TryAddSingleton<QueueTriggerAttributeBindingProvider>();
services.TryAddEnumerable(ServiceDescriptor.Singleton<IBindingProvider, CloudStorageAccountBindingProvider>());
})
.AddExtension<TableExtension>()
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IBindingProvider, CloudStorageAccountBindingProvider>());
return builder.AddExtension<TableExtension>()
.AddExtension<QueueExtension>()
.AddExtension<BlobExtensionConfig>()
.AddExtension<BlobTriggerExtensionConfig>();
}

Просмотреть файл

@ -11,7 +11,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.Storage
{
public class StorageWebJobsStartup : IWebJobsStartup
{
public void Configure(IHostBuilder builder)
public void Configure(IWebJobsBuilder builder)
{
builder.AddAzureStorage();
}

Просмотреть файл

@ -1,24 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Azure.WebJobs.Host.Indexers;
using Microsoft.Azure.WebJobs;
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using Microsoft.Azure.WebJobs.Host.Config;
using Microsoft.WindowsAzure.Storage;
using Microsoft.Azure.WebJobs.Host.Executors;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.WebJobs.Host.Loggers;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Host.Configuration;
using WebJobs.Host.Storage;
using Microsoft.Azure.WebJobs.Host.Executors;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
namespace Microsoft.Extensions.Hosting
@ -27,37 +19,32 @@ namespace Microsoft.Extensions.Hosting
{
// WebJobs v1 Classic logging. Needed for dashboard.
// $$$ Update title?
public static IHostBuilder AddWebJobsLogging(this IHostBuilder builder)
public static IWebJobsBuilder AddWebJobsLogging(this IWebJobsBuilder builder)
{
return builder
.ConfigureServices((context, services) =>
{
services.AddWebJobsLogging();
});
builder.Services.AddWebJobsLogging();
return builder;
}
// Make the Runtime itself use storage for its internal operations.
// Uses v1 app settings, via a LegacyConfigSetup object.
public static IHostBuilder AddAzureStorageCoreServices(this IHostBuilder builder)
public static IWebJobsBuilder AddAzureStorageCoreServices(this IWebJobsBuilder builder)
{
return builder
.ConfigureServices((context, services) =>
{
// Replace existing runtime services with storage-backed implementations.
// Add runtime services that depend on storage.
services.AddSingleton<IDistributedLockManager>(provider => Create(provider));
services.TryAddSingleton<IHostIdProvider, DynamicHostIdProvider>();
// Replace existing runtime services with storage-backed implementations.
// Add runtime services that depend on storage.
builder.Services.AddSingleton<IDistributedLockManager>(provider => Create(provider));
builder.Services.TryAddSingleton<IHostIdProvider, DynamicHostIdProvider>();
// Used specifically for the CloudBlobContainerDistributedLockManager implementaiton
services.TryAddSingleton<DistributedLockManagerContainerProvider>();
// Used specifically for the CloudBlobContainerDistributedLockManager implementaiton
builder.Services.TryAddSingleton<DistributedLockManagerContainerProvider>();
services.TryAddEnumerable(
ServiceDescriptor.Transient<IConfigureOptions<LegacyConfig>, LegacyConfigSetup>());
builder.Services.TryAddEnumerable(
ServiceDescriptor.Transient<IConfigureOptions<LegacyConfig>, LegacyConfigSetup>());
services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<JobHostInternalStorageOptions>, JobHostInternalStorageOptionsSetup>());
});
builder.Services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<JobHostInternalStorageOptions>, JobHostInternalStorageOptionsSetup>());
return builder;
}
// This is only called if the host didn't already provide an implementation

Просмотреть файл

@ -0,0 +1,18 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
namespace Microsoft.Azure.WebJobs
{
public interface IWebJobsBuilder
{
/// <summary>
/// Gets the <see cref="IServiceCollection"/> where WebJobs services are configured.
/// </summary>
IServiceCollection Services { get; }
}
}

Просмотреть файл

@ -9,6 +9,6 @@ namespace Microsoft.Azure.WebJobs.Hosting
{
public interface IWebJobsStartup
{
void Configure(IHostBuilder builder);
void Configure(IWebJobsBuilder builder);
}
}

Просмотреть файл

@ -15,7 +15,7 @@ namespace Microsoft.Azure.WebJobs.Hosting
{
configure = configure ?? new Action<JobHostOptions>(o => { });
return new HostBuilder()
.ConfigureWebJobsHost(configure);
.ConfigureWebJobs(o => { }, configure);
}
}
}

Просмотреть файл

@ -0,0 +1,22 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.Azure.WebJobs.Host
{
internal class WebJobsBuilder : IWebJobsBuilder
{
private readonly IServiceCollection _services;
public WebJobsBuilder(IServiceCollection services)
{
_services = services ?? throw new ArgumentNullException(nameof(services));
}
public IServiceCollection Services => _services;
}
}

Просмотреть файл

@ -0,0 +1,157 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Azure.WebJobs.Host.Bindings;
using Microsoft.Azure.WebJobs.Host.Bindings.Cancellation;
using Microsoft.Azure.WebJobs.Host.Bindings.Data;
using Microsoft.Azure.WebJobs.Host.Config;
using Microsoft.Azure.WebJobs.Host.Loggers;
using Microsoft.Azure.WebJobs.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.Azure.WebJobs
{
public static class WebJobsBuilderExtensions
{
public static IWebJobsBuilder AddExtension<TExtension>(this IWebJobsBuilder builder)
where TExtension : class, IExtensionConfigProvider
{
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IExtensionConfigProvider, TExtension>());
return builder;
}
public static IWebJobsBuilder AddExtension(this IWebJobsBuilder builder, IExtensionConfigProvider instance)
{
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IExtensionConfigProvider>(instance));
return builder;
}
public static IWebJobsBuilder UseWebJobsStartup<T>(this IWebJobsBuilder builder) where T : IWebJobsStartup, new()
{
return builder.UseWebJobsStartup(typeof(T));
}
public static IWebJobsBuilder UseWebJobsStartup(this IWebJobsBuilder builder, Type startupType)
{
if (!typeof(IWebJobsStartup).IsAssignableFrom(startupType))
{
throw new ArgumentException($"The {nameof(startupType)} argument must be an implementation of {typeof(IWebJobsStartup).FullName}");
}
IWebJobsStartup startup = (IWebJobsStartup)Activator.CreateInstance(startupType);
startup.Configure(builder);
return builder;
}
/// <summary>
/// Enables use of external configuration providers, allowing them to inject services and update
/// configuration during the host initialization process.
/// Type discovery is performed using the <see cref="DefaultStartupTypeDiscoverer"/>.
/// </summary>
/// <param name="builder">The <see cref="IWebJobsBuilder"/> instance to configure.</param>
/// <returns>The updated <see cref="IHostBuilder"/> instance.</returns>
public static IWebJobsBuilder UseExternalStartup(this IWebJobsBuilder builder)
{
return builder.UseExternalStartup(new DefaultStartupTypeDiscoverer());
}
/// <summary>
/// Enables use of external configuration providers, allowing them to inject services and update
/// configuration during the host initialization process.
/// </summary>
/// <param name="builder">The <see cref="IWebJobsBuilder"/> instance to configure.</param>
/// <param name="typeDiscoverer">An implementation of <see cref="IWebJobsStartupTypeDiscoverer"/> that provides a list of types that
/// should be used in the startup process.</param>
/// <returns>The updated <see cref="IHostBuilder"/> instance.</returns>
public static IWebJobsBuilder UseExternalStartup(this IWebJobsBuilder builder, IWebJobsStartupTypeDiscoverer typeDiscoverer)
{
Type[] types = typeDiscoverer.GetStartupTypes();
foreach (var type in types)
{
builder.UseWebJobsStartup(type);
}
return builder;
}
// This is an alternative to AddWebJobsLogging
public static IWebJobsBuilder AddFastLogging(this IWebJobsBuilder builder, IEventCollectorFactory fastLogger)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (fastLogger == null)
{
throw new ArgumentNullException(nameof(fastLogger));
}
builder.Services.AddSingleton<IFunctionOutputLoggerProvider, FastTableLoggerProvider>();
builder.Services.AddSingleton<IFunctionOutputLogger, FastTableLoggerProvider>();
builder.Services.AddSingleton(fastLogger);
return builder;
}
/// <summary>
/// Adds the ability to bind to an <see cref="ExecutionContext"/> from a WebJobs function.
/// </summary>
/// <param name="builder">The <see cref="IWebJobsBuilder"/> to configure.</param>
/// <param name="configure">An optional <see cref="Action{ExecutionContextBindingOptions}"/> to configure the provided <see cref="ExecutionContextOptions"/>.</param>
/// <returns></returns>
public static IWebJobsBuilder AddExecutionContextBinding(this IWebJobsBuilder builder, Action<ExecutionContextOptions> configure = null)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
builder.Services.AddSingleton<IBindingProvider, ExecutionContextBindingProvider>();
if (configure != null)
{
builder.Services.Configure(configure);
}
return builder;
}
/// <summary>
/// Adds builtin bindings
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static IWebJobsBuilder AddBuiltInBindings(this IWebJobsBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
// for typeof(CancellationToken)
builder.Services.AddSingleton<IBindingProvider, CancellationTokenBindingProvider>();
// The TraceWriter binder handles all remaining TraceWriter/TextWriter parameters. It must come after the
// Blob binding provider; otherwise bindings like Do([Blob("a/b")] TextWriter blob) wouldn't work.
// for typeof(TraceWriter), typeof(TextWriter)
builder.Services.AddSingleton<IBindingProvider, TraceWriterBindingProvider>();
// for typeof(ILogger)
builder.Services.AddSingleton<IBindingProvider, ILoggerBindingProvider>();
// arbitrary binding to binding data
builder.Services.AddSingleton<IBindingProvider, DataBindingProvider>();
return builder;
}
}
}

Просмотреть файл

@ -15,12 +15,17 @@ namespace Microsoft.Extensions.Hosting
{
public static class WebJobsHostBuilderExtensions
{
public static IHostBuilder ConfigureWebJobsHost(this IHostBuilder builder)
public static IHostBuilder ConfigureWebJobs(this IHostBuilder builder)
{
return builder.ConfigureWebJobsHost(o => { });
return builder.ConfigureWebJobs(o => { }, o => { });
}
public static IHostBuilder ConfigureWebJobsHost(this IHostBuilder builder, Action<JobHostOptions> configure)
public static IHostBuilder ConfigureWebJobs(this IHostBuilder builder, Action<IWebJobsBuilder> configure)
{
return builder.ConfigureWebJobs(configure, o => { });
}
public static IHostBuilder ConfigureWebJobs(this IHostBuilder builder, Action<IWebJobsBuilder> configure, Action<JobHostOptions> configureOptions)
{
builder.ConfigureAppConfiguration(config =>
{
@ -30,124 +35,10 @@ namespace Microsoft.Extensions.Hosting
builder.ConfigureServices((context, services) =>
{
// TODO: FACAVAL
// services.Configure<JobHostOptions>(context.Configuration);
IWebJobsBuilder webJobsBuilder = services.AddWebJobs(configureOptions);
configure(webJobsBuilder);
services.AddWebJobs(configure);
services.AddSingleton<IHostedService, JobHostService>();
});
return builder;
}
public static IHostBuilder AddExtension<TExtension>(this IHostBuilder builder)
where TExtension : class, IExtensionConfigProvider
{
builder.ConfigureServices(services =>
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IExtensionConfigProvider, TExtension>());
});
return builder;
}
public static IHostBuilder AddExtension(this IHostBuilder builder, IExtensionConfigProvider instance)
{
builder.ConfigureServices(services =>
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IExtensionConfigProvider>(instance));
});
return builder;
}
public static IHostBuilder UseWebJobsStartup<T>(this IHostBuilder builder) where T : IWebJobsStartup, new()
{
return builder.UseWebJobsStartup(typeof(T));
}
public static IHostBuilder UseWebJobsStartup(this IHostBuilder builder, Type startupType)
{
if (!typeof(IWebJobsStartup).IsAssignableFrom(startupType))
{
throw new ArgumentException($"The {nameof(startupType)} argument must be an implementation of {typeof(IWebJobsStartup).FullName}");
}
IWebJobsStartup startup = (IWebJobsStartup)Activator.CreateInstance(startupType);
startup.Configure(builder);
return builder;
}
/// <summary>
/// Enables use of external configuration providers, allowing them to inject services and update
/// configuration during the host initialization process.
/// Type discovery is performed using the <see cref="DefaultStartupTypeDiscoverer"/>.
/// </summary>
/// <param name="builder">The <see cref="IHostBuilder"/> instance to configure.</param>
/// <returns>The updated <see cref="IHostBuilder"/> instance.</returns>
public static IHostBuilder UseExternalStartup(this IHostBuilder builder)
{
return builder.UseExternalStartup(new DefaultStartupTypeDiscoverer());
}
/// <summary>
/// Enables use of external configuration providers, allowing them to inject services and update
/// configuration during the host initialization process.
/// </summary>
/// <param name="builder">The <see cref="IHostBuilder"/> instance to configure.</param>
/// <param name="typeDiscoverer">An implementation of <see cref="IWebJobsStartupTypeDiscoverer"/> that provides a list of types that
/// should be used in the startup process.</param>
/// <returns>The updated <see cref="IHostBuilder"/> instance.</returns>
public static IHostBuilder UseExternalStartup(this IHostBuilder builder, IWebJobsStartupTypeDiscoverer typeDiscoverer)
{
Type[] types = typeDiscoverer.GetStartupTypes();
foreach (var type in types)
{
builder.UseWebJobsStartup(type);
}
return builder;
}
public static IHostBuilder ConfigureWebJobsFastLogging(this IHostBuilder builder, IEventCollectorFactory fastLogger)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (fastLogger == null)
{
throw new ArgumentNullException(nameof(fastLogger));
}
builder.ConfigureServices(services =>
{
services.AddWebJobsFastLogging(fastLogger);
});
return builder;
}
/// <summary>
/// Adds the ability to bind to an <see cref="ExecutionContext"/> from a WebJobs function.
/// </summary>
/// <param name="builder">The <see cref="IHostBuilder"/> to configure.</param>
/// <param name="configure">An optional <see cref="Action{ExecutionContextBindingOptions}"/> to configure the provided <see cref="ExecutionContextOptions"/>.</param>
/// <returns></returns>
public static IHostBuilder AddExecutionContextBinding(this IHostBuilder builder, Action<ExecutionContextOptions> configure = null)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
builder.ConfigureServices(services =>
{
services.AddExecutionContextBinding(configure);
services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, JobHostService>());
});
return builder;

Просмотреть файл

@ -34,7 +34,7 @@ namespace Microsoft.Azure.WebJobs
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddWebJobs(this IServiceCollection services, Action<JobHostOptions> configure)
public static IWebJobsBuilder AddWebJobs(this IServiceCollection services, Action<JobHostOptions> configure)
{
if (services == null)
{
@ -106,87 +106,13 @@ namespace Microsoft.Azure.WebJobs
services.TryAddSingleton<IEventCollectorFactory, EventCollectorFactory>();
services.TryAddSingleton<IAsyncCollector<FunctionInstanceLogEntry>>(p => p.GetRequiredService<IEventCollectorFactory>().Create());
// Options setup
services.RegisterBuiltInBindings();
// Core host services
services.TryAddSingleton<IJobHost, JobHost>();
return services;
}
var builder = new WebJobsBuilder(services);
builder.AddBuiltInBindings();
// This is an alternative to AddWebJobsLogging
public static IServiceCollection AddWebJobsFastLogging(this IServiceCollection services, IEventCollectorFactory fastLogger)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
if (fastLogger == null)
{
throw new ArgumentNullException(nameof(fastLogger));
}
services.AddSingleton<IFunctionOutputLoggerProvider, FastTableLoggerProvider>();
services.AddSingleton<IFunctionOutputLogger, FastTableLoggerProvider>();
services.AddSingleton(fastLogger);
return services;
}
/// <summary>
/// Adds builtin bindings
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection RegisterBuiltInBindings(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
// for typeof(CancellationToken)
services.AddSingleton<IBindingProvider, CancellationTokenBindingProvider>();
// The TraceWriter binder handles all remaining TraceWriter/TextWriter parameters. It must come after the
// Blob binding provider; otherwise bindings like Do([Blob("a/b")] TextWriter blob) wouldn't work.
// for typeof(TraceWriter), typeof(TextWriter)
services.AddSingleton<IBindingProvider, TraceWriterBindingProvider>();
// for typeof(ILogger)
services.AddSingleton<IBindingProvider, ILoggerBindingProvider>();
// arbitrary binding to binding data
services.AddSingleton<IBindingProvider, DataBindingProvider>();
return services;
}
/// <summary>
/// Adds the ability to bind to an <see cref="ExecutionContext"/> from a WebJobs function.
/// </summary>
/// <param name="services">The service collection to configure.</param>
/// <param name="configure">An optional <see cref="Action{ExecutionContextBindingOptions}"/> to configure the provided <see cref="ExecutionContextOptions"/>.</param>
/// <returns></returns>
public static IServiceCollection AddExecutionContextBinding(this IServiceCollection services, Action<ExecutionContextOptions> configure = null)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
services.AddSingleton<IBindingProvider, ExecutionContextBindingProvider>();
if (configure != null)
{
services.Configure(configure);
}
return services;
return builder;
}
}
}

Просмотреть файл

@ -12,19 +12,19 @@ namespace Microsoft.Extensions.Hosting
{
public static class ServiceBusHostBuilderExtensions
{
public static IHostBuilder AddServiceBus(this IHostBuilder builder)
public static IWebJobsBuilder AddServiceBus(this IWebJobsBuilder builder)
{
return builder.AddExtension<ServiceBusExtensionConfig>()
.ConfigureServices(services =>
{
services.AddOptions<ServiceBusOptions>()
builder.AddExtension<ServiceBusExtensionConfig>();
builder.Services.AddOptions<ServiceBusOptions>()
.Configure<IConnectionStringProvider>((o, p) =>
{
o.ConnectionString = p.GetConnectionString(ConnectionStringNames.ServiceBus);
});
services.TryAddSingleton<MessagingProvider>();
});
builder.Services.TryAddSingleton<MessagingProvider>();
return builder;
}
}
}

Просмотреть файл

@ -11,7 +11,7 @@ namespace Microsoft.Azure.WebJobs.Extensions.ServiceBus
{
public class ServiceBusWebJobsStartup : IWebJobsStartup
{
public void Configure(IHostBuilder builder)
public void Configure(IWebJobsBuilder builder)
{
builder.AddServiceBus();
}

Просмотреть файл

@ -39,12 +39,14 @@ namespace Microsoft.Azure.WebJobs.EventHubs.UnitTests
public void Initialize_PerformsExpectedRegistrations()
{
var host = new HostBuilder()
.ConfigureDefaultTestHost()
.ConfigureDefaultTestHost(builder =>
{
builder.AddEventHubs();
})
.ConfigureServices(c =>
{
c.AddSingleton<INameResolver>(new RandomNameResolver());
})
.AddEventHubs()
.Build();
IExtensionRegistry extensions = host.Services.GetService<IExtensionRegistry>();

Просмотреть файл

@ -220,8 +220,10 @@ namespace Microsoft.Azure.WebJobs.EventHubs.UnitTests
{
// TODO: It's tough to wire all this up without using a new host.
IHost host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddEventHubs()
.ConfigureDefaultTestHost(builder =>
{
builder.AddEventHubs();
})
.ConfigureAppConfiguration(c =>
{
c.AddInMemoryCollection(new Dictionary<string, string>

Просмотреть файл

@ -19,7 +19,7 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
"EventHubTriggerAttribute",
"EventHubConfiguration",
"EventHubExtensionConfigProvider",
"EventHubHostBuilderExtensions",
"EventHubWebJobsBuilderExtensions",
"EventHubsWebJobsStartup"
};

Просмотреть файл

@ -365,7 +365,10 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests.ApplicationInsights
_resolver = new RandomNameResolver();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<HttpDependencyCollectionTests>()
.ConfigureDefaultTestHost<HttpDependencyCollectionTests>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<INameResolver>(_resolver);
@ -375,7 +378,6 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests.ApplicationInsights
});
})
.AddApplicationInsights(_mockApplicationInsightsKey, filter.Filter, null)
.AddAzureStorage()
.Build();
TelemetryConfiguration telemteryConfiguration = host.Services.GetService<TelemetryConfiguration>();

Просмотреть файл

@ -36,8 +36,10 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
_resolver = new RandomNameResolver();
_host = new HostBuilder()
.ConfigureDefaultTestHost<AsyncCancellationEndToEndTests>()
.AddAzureStorage()
.ConfigureDefaultTestHost<AsyncCancellationEndToEndTests>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<INameResolver, RandomNameResolver>();

Просмотреть файл

@ -59,8 +59,10 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
_resolver = new RandomNameResolver();
_hostBuilder = new HostBuilder()
.ConfigureDefaultTestHost<AsyncChainEndToEndTests>()
.AddAzureStorage()
.ConfigureDefaultTestHost<AsyncChainEndToEndTests>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<INameResolver>(_resolver);
@ -717,8 +719,10 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
// We know the tests are using the default storage provider, so pull that out
// of a default host.
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<TestFixture>()
.AddAzureStorage()
.ConfigureDefaultTestHost<TestFixture>(b =>
{
b.AddAzureStorage();
})
.Build();
var provider = host.Services.GetService<StorageAccountProvider>();

Просмотреть файл

@ -208,12 +208,14 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
_resolver = new RandomNameResolver();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<AzureStorageEndToEndTests>()
.ConfigureDefaultTestHost<AzureStorageEndToEndTests>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<INameResolver>(_resolver);
})
.AddAzureStorage()
.Build();
// write test entities
@ -286,12 +288,14 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
_resolver = new RandomNameResolver();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<AzureStorageEndToEndTests>()
.ConfigureDefaultTestHost<AzureStorageEndToEndTests>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<INameResolver>(_resolver);
})
.AddAzureStorage()
.Build();
if (uploadBlobBeforeHostStart)
@ -338,7 +342,10 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
// Reinitialize the name resolver to avoid conflicts
_resolver = new RandomNameResolver();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<AzureStorageEndToEndTests>()
.ConfigureDefaultTestHost<AzureStorageEndToEndTests>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<INameResolver>(_resolver);
@ -348,7 +355,6 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
o.QueueProcessorFactory = new TestQueueProcessorFactory();
});
})
.AddAzureStorage()
.Build();
TestLoggerProvider loggerProvider = host.GetTestLoggerProvider();
@ -531,8 +537,10 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
public TestFixture()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<TestFixture>()
.AddAzureStorage()
.ConfigureDefaultTestHost<TestFixture>(b =>
{
b.AddAzureStorage();
})
.Build();
var provider = host.Services.GetService<StorageAccountProvider>();

Просмотреть файл

@ -692,16 +692,19 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
{
RandomNameResolver nameResolver = new RandomNameResolver();
Host = RuntimeStorageHostBuilderExtensions.AddAzureStorageCoreServices(new HostBuilder()
.ConfigureDefaultTestHost<BlobBindingEndToEndTests>()
.AddAzureStorage()
)
.ConfigureServices(services =>
Host = new HostBuilder()
.ConfigureDefaultTestHost<BlobBindingEndToEndTests>(b =>
{
services.AddSingleton<INameResolver>(nameResolver);
b.AddAzureStorage();
RuntimeStorageHostBuilderExtensions.AddAzureStorageCoreServices(b);
})
.ConfigureServices(services =>
{
services.AddSingleton<INameResolver>(nameResolver);
})
.Build();
JobHost = Host.GetJobHost();
var provider = Host.Services.GetService<StorageAccountProvider>();

Просмотреть файл

@ -47,8 +47,10 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
// pull from a default host
var host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddAzureStorage()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage();
})
.Build();
var provider = host.Services.GetService<StorageAccountProvider>();
_storageAccount = provider.GetHost().SdkObject;
@ -64,8 +66,10 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
activator.Add(program);
return new HostBuilder()
.ConfigureDefaultTestHost<TProgram>()
.AddAzureStorage()
.ConfigureDefaultTestHost<TProgram>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<IJobActivator>(activator);

Просмотреть файл

@ -71,9 +71,11 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
public async Task DispatchQueueBatchTriggerTest()
{
_host = new HostBuilder()
.ConfigureDefaultTestHost<SampleTrigger>()
.AddAzureStorage()
.AddExtension<DispatchQueueTestConfig>()
.ConfigureDefaultTestHost<SampleTrigger>(b =>
{
b.AddAzureStorage()
.AddExtension<DispatchQueueTestConfig>();
})
.ConfigureServices(services =>
{
// each test will have a unique hostId so that consecutive test run will not be affected by clean up code
@ -104,9 +106,11 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
public async void PoisonQueueTest()
{
_host = new HostBuilder()
.ConfigureDefaultTestHost<SampleTriggerWithPoisonQueue>()
.AddAzureStorage()
.AddExtension<DispatchQueueTestConfig>()
.ConfigureDefaultTestHost<SampleTriggerWithPoisonQueue>(b =>
{
b.AddAzureStorage()
.AddExtension<DispatchQueueTestConfig>();
})
.ConfigureServices(services =>
{
// each test will have a unique hostId so that consecutive test run will not be affected by clean up code

Просмотреть файл

@ -139,9 +139,11 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
Assert.True(!string.IsNullOrEmpty(connection), "Required test connection string is missing.");
var host = new HostBuilder()
.ConfigureDefaultTestHost<EventHubTestJobs>()
.AddAzureStorage()
.AddEventHubs()
.ConfigureDefaultTestHost<EventHubTestJobs>(b =>
{
b.AddAzureStorage()
.AddEventHubs();
})
.ConfigureServices(services =>
{
services.AddSingleton<EventHubConfiguration>(serviceProvider =>

Просмотреть файл

@ -47,9 +47,12 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
var fakeSasUri = container.Uri + sig;
var prog = new BasicProg();
IHost host = RuntimeStorageHostBuilderExtensions.AddAzureStorageCoreServices(new HostBuilder()
.ConfigureDefaultTestHost(prog)
.AddAzureStorage()
IHost host = new HostBuilder()
.ConfigureDefaultTestHost(prog, b =>
{
b.AddAzureStorage();
RuntimeStorageHostBuilderExtensions.AddAzureStorageCoreServices(b);
})
.ConfigureAppConfiguration(config =>
{
// Set env to the SAS container and clear out all other storage.
@ -60,7 +63,6 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
{ "AzureWebJobsDashboard", null }
});
})
)
.Build();
var internalOptions = host.Services.GetService<DistributedLockManagerContainerProvider>();

Просмотреть файл

@ -251,12 +251,14 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
RandomNameResolver nameResolver = new TestNameResolver();
Host = new HostBuilder()
.ConfigureDefaultTestHost<MultipleStorageAccountsEndToEndTests>()
.ConfigureDefaultTestHost<MultipleStorageAccountsEndToEndTests>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<INameResolver>(nameResolver);
})
.AddAzureStorage()
.Build();
Account1 = Host.GetStorageAccount();

Просмотреть файл

@ -67,8 +67,10 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
RandomNameResolver nameResolver = new RandomNameResolver();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ParallelExecutionTests>()
.AddAzureStorage()
.ConfigureDefaultTestHost<ParallelExecutionTests>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<INameResolver>(nameResolver);

Просмотреть файл

@ -105,9 +105,11 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
try
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ServiceBusTestJobs>()
.AddAzureStorage()
.AddServiceBus()
.ConfigureDefaultTestHost<ServiceBusTestJobs>(b =>
{
b.AddAzureStorage()
.AddServiceBus();
})
.ConfigureServices(services =>
{
services.AddSingleton<MessagingProvider, CustomMessagingProvider>();
@ -136,9 +138,11 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
try
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ServiceBusTestJobs>(nameResolver: _nameResolver)
.AddAzureStorage()
.AddServiceBus()
.ConfigureDefaultTestHost<ServiceBusTestJobs>(b =>
{
b.AddAzureStorage()
.AddServiceBus();
}, nameResolver: _nameResolver)
.ConfigureServices(services =>
{
services.AddSingleton<MessagingProvider, CustomMessagingProvider>();
@ -203,9 +207,11 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
private IHost CreateHost()
{
return new HostBuilder()
.ConfigureDefaultTestHost<ServiceBusTestJobs>()
.AddAzureStorage()
.AddServiceBus()
.ConfigureDefaultTestHost<ServiceBusTestJobs>(b =>
{
b.AddAzureStorage()
.AddServiceBus();
})
.ConfigureServices(services =>
{
services.AddSingleton<INameResolver>(_nameResolver);

Просмотреть файл

@ -633,9 +633,13 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
{
TestJobActivator activator = new TestJobActivator(hostId);
var hostBuilder = RuntimeStorageHostBuilderExtensions.AddAzureStorageCoreServices(new HostBuilder()
.ConfigureDefaultTestHost<TProg>()
.AddAzureStorage()
var hostBuilder = new HostBuilder()
.ConfigureDefaultTestHost<TProg>(b =>
{
b.AddAzureStorage()
.AddExtension<TestTriggerAttributeBindingProvider>();
RuntimeStorageHostBuilderExtensions.AddAzureStorageCoreServices(b);
})
.ConfigureTestLogger()
.ConfigureServices(services =>
{
@ -648,9 +652,7 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
o.LockAcquisitionTimeout = TimeSpan.FromSeconds(10);
o.LockAcquisitionPollingInterval = TimeSpan.FromMilliseconds(500);
});
})
.AddExtension<TestTriggerAttributeBindingProvider>()
);
});
extraConfig?.Invoke(hostBuilder); // test hook gets final say to replace.
@ -827,8 +829,10 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
// Create a default host since we know that's where the account
// is coming from
IHost host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddAzureStorage()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage();
})
.Build();
return host.GetStorageAccount();
@ -839,8 +843,10 @@ namespace Microsoft.Azure.WebJobs.Host.EndToEndTests
// Create a default host since we know that's where the account
// is coming from
IHost host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddAzureStorage()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage();
})
.Build();
return host.Services.GetService<IConfiguration>()[key];

Просмотреть файл

@ -211,9 +211,11 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
IHostIdProvider hostIdProvider = new FakeHostIdProvider();
IWebJobsExceptionHandler exceptionHandler = new TaskBackgroundExceptionHandler<TResult>(taskSource);
return StorageHostBuilderExtensions.AddAzureStorage(new HostBuilder()
.ConfigureDefaultTestHost(programType)
.AddAzureStorage()
return new HostBuilder()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage();
}, programType)
.ConfigureServices(services =>
{
// services.AddSingleton<IOptionsFactory<JobHostQueuesOptions>, FakeQueuesOptionsFactory>(); $$$ ???
@ -229,7 +231,6 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
services.AddSingleton<IFunctionOutputLoggerProvider>(new NullFunctionOutputLoggerProvider());
services.AddSingleton(hostIdProvider);
})
)
.Build();
}

Просмотреть файл

@ -108,8 +108,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
const int N = 5;
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ILoggerFunctions>()
.AddAzureStorage()
.ConfigureDefaultTestHost<ILoggerFunctions>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<IAsyncCollector<FunctionInstanceLogEntry>>(mockAggregator.Object);

Просмотреть файл

@ -32,8 +32,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
IExtensionRegistry extensionRegistry = null, ILoggerFactory loggerFactory = null)
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddAzureStorage()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<StorageAccountProvider>(new FakeStorageAccountProvider());
@ -49,7 +51,6 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
services.AddSingleton<IExtensionRegistry>(extensionRegistry);
}
})
.AddAzureStorage()
.Build();
ITriggerBindingProvider triggerBindingProvider = host.Services.GetService<ITriggerBindingProvider>();

Просмотреть файл

@ -23,8 +23,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
public void AttrBuilder()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddAzureStorage()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage();
})
.Build();
var metadataProvider = host.CreateMetadataProvider();
@ -93,8 +95,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
public void DefaultTypeForTable()
{
var host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddAzureStorage()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage();
})
.Build();
var metadataProvider = host.CreateMetadataProvider();
@ -114,8 +118,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
public void DefaultTypeForQueue()
{
var host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddAzureStorage()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage();
})
.Build();
var metadataProvider = host.CreateMetadataProvider();

Просмотреть файл

@ -93,14 +93,16 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
using (EnvVarHolder.Set("AzureWebJobs:InternalSasBlobContainer", fakeSasUri))
{
var hostBuilder = RuntimeStorageHostBuilderExtensions.AddAzureStorageCoreServices(new HostBuilder()
.ConfigureDefaultTestHost()
.AddAzureStorage()
var hostBuilder = new HostBuilder()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage()
.AddAzureStorageCoreServices();
})
.ConfigureAppConfiguration(c =>
{
c.AddEnvironmentVariables();
})
);
});
IHost host = hostBuilder.Build();
@ -115,14 +117,16 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
// Verify that JobHostConfig pulls a Sas container from appsettings.
[Fact]
public void JobHost_UsesSas_SetService()
{
var hostBuilder = RuntimeStorageHostBuilderExtensions.AddAzureStorageCoreServices(new HostBuilder()
.ConfigureDefaultTestHost()
.AddAzureStorage()
{
var hostBuilder = new HostBuilder()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage()
.AddAzureStorageCoreServices();
})
.ConfigureAppConfiguration(c =>
{
})
);
});
// Explicitly set the service
hostBuilder.ConfigureServices((ctx, services) =>
@ -149,17 +153,19 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
{
var fakeSasUri = "https://contoso.blob.core.windows.net/myContainer3?signature=foo";
var hostBuilder = RuntimeStorageHostBuilderExtensions.AddAzureStorageCoreServices(new HostBuilder()
.ConfigureDefaultTestHost()
.AddAzureStorage()
var hostBuilder = new HostBuilder()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage()
.AddAzureStorageCoreServices();
})
.ConfigureAppConfiguration(c =>
{
c.AddInMemoryCollection(new Dictionary<string, string>
{
{ "AzureWebJobs:InternalSasBlobContainer", fakeSasUri }
});
})
);
});
IHost host = hostBuilder.Build();
@ -182,10 +188,12 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
{
IHost host = new HostBuilder()
.ConfigureWebJobsHost()
.ConfigureTypeLocator(typeof(BasicTest))
.ConfigureWebJobsFastLogging(fastLogger)
.Build();
.ConfigureWebJobs(b =>
{
b.AddFastLogging(fastLogger);
})
.ConfigureTypeLocator(typeof(BasicTest))
.Build();
var randomValue = Guid.NewGuid().ToString();

Просмотреть файл

@ -463,8 +463,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
.Returns(errorLogger);
var builder = new HostBuilder()
.ConfigureDefaultTestHost<BindingErrorsProgram>()
.AddAzureStorage()
.ConfigureDefaultTestHost<BindingErrorsProgram>(b =>
{
b.AddAzureStorage();
})
.ConfigureLogging(logging =>
{
logging.AddProvider(mockProvider.Object);

Просмотреть файл

@ -15,9 +15,11 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
{
public static IHostBuilder ConfigureDefaultTestHost<TProgram>(this IHostBuilder builder, StorageAccount account)
{
return builder.ConfigureDefaultTestHost<TProgram>()
.AddAzureStorage()
.ConfigureServices(services => services.AddFakeStorageAccountProvider(account));
return builder.ConfigureDefaultTestHost<TProgram>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services => services.AddFakeStorageAccountProvider(account));
}
public static IHostBuilder ConfigureFakeStorageAccount(this IHostBuilder builder)

Просмотреть файл

@ -110,24 +110,28 @@ namespace Microsoft.Azure.WebJobs.Host.TestCommon
}
Assert.True(false, "Invoker should have failed");
}
public static IHostBuilder ConfigureDefaultTestHost(this IHostBuilder builder, params Type[] types)
{
return builder.ConfigureWebJobsHost()
.ConfigureServices(services =>
{
services.AddSingleton<ITypeLocator>(new FakeTypeLocator(types));
return builder.ConfigureDefaultTestHost(b => { }, types);
}
// Register this to fail a test if a background exception is thrown
services.AddSingleton<IWebJobsExceptionHandlerFactory, TestExceptionHandlerFactory>();
})
.ConfigureTestLogger();
public static IHostBuilder ConfigureDefaultTestHost(this IHostBuilder builder, Action<IWebJobsBuilder> configureWebJobs, params Type[] types)
{
return builder.ConfigureWebJobs(configureWebJobs)
.ConfigureServices(services =>
{
services.AddSingleton<ITypeLocator>(new FakeTypeLocator(types));
// Register this to fail a test if a background exception is thrown
services.AddSingleton<IWebJobsExceptionHandlerFactory, TestExceptionHandlerFactory>();
})
.ConfigureTestLogger();
}
public static IHostBuilder ConfigureDefaultTestHost<TProgram>(this IHostBuilder builder,
TProgram instance)
TProgram instance, Action<IWebJobsBuilder> configureWebJobs)
{
return builder.ConfigureDefaultTestHost(typeof(TProgram))
return builder.ConfigureDefaultTestHost(configureWebJobs, typeof(TProgram))
.ConfigureServices(services =>
{
services.AddSingleton<IJobHost, JobHost<TProgram>>();
@ -136,10 +140,19 @@ namespace Microsoft.Azure.WebJobs.Host.TestCommon
});
}
public static IHostBuilder ConfigureDefaultTestHost<TProgram>(this IHostBuilder builder,
public static IHostBuilder ConfigureDefaultTestHost<TProgram>(this IHostBuilder builder)
{
return builder.ConfigureDefaultTestHost(o=> { }, typeof(TProgram))
.ConfigureServices(services =>
{
services.AddSingleton<IJobHost, JobHost<TProgram>>();
});
}
public static IHostBuilder ConfigureDefaultTestHost<TProgram>(this IHostBuilder builder, Action<IWebJobsBuilder> configureWebJobs,
INameResolver nameResolver = null, IJobActivator activator = null)
{
return builder.ConfigureDefaultTestHost(typeof(TProgram))
return builder.ConfigureDefaultTestHost(configureWebJobs, typeof(TProgram))
.ConfigureServices(services =>
{
services.AddSingleton<IJobHost, JobHost<TProgram>>();
@ -164,8 +177,8 @@ namespace Microsoft.Azure.WebJobs.Host.TestCommon
});
}
public static IHostBuilder ConfigureCatchFailures<TResult>(
this IHostBuilder builder,
public static IWebJobsBuilder ConfigureCatchFailures<TResult>(
this IWebJobsBuilder builder,
TaskCompletionSource<TResult> src,
bool signalOnFirst,
IEnumerable<string> ignoreFailureFunctions)
@ -174,10 +187,10 @@ namespace Microsoft.Azure.WebJobs.Host.TestCommon
src,
signalOnFirst,
ignoreFailureFunctions);
return builder.ConfigureServices(services =>
{
services.AddSingleton<IFunctionInstanceLogger>(logger);
});
builder.Services.AddSingleton<IFunctionInstanceLogger>(logger);
return builder;
}

Просмотреть файл

@ -17,8 +17,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Bindings
public async Task CanBindExecutionContext()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<CoreTestJobs>()
.AddExecutionContextBinding()
.ConfigureDefaultTestHost<CoreTestJobs>(b =>
{
b.AddExecutionContextBinding();
})
.Build();
var jobHost = host.GetJobHost<CoreTestJobs>();
@ -37,10 +39,12 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Bindings
public async Task SetAppDirectory()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<CoreTestJobs>()
.AddExecutionContextBinding(o =>
.ConfigureDefaultTestHost<CoreTestJobs>(b =>
{
o.AppDirectory = @"z:\home";
b.AddExecutionContextBinding(o =>
{
o.AppDirectory = @"z:\home";
});
})
.Build();

Просмотреть файл

@ -541,8 +541,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
IExtensionConfigProvider ext = prog;
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<TConfig>(activator: jobActivator)
.AddExtension(ext)
.ConfigureDefaultTestHost<TConfig>(b =>
{
b.AddExtension(ext);
}, activator: jobActivator)
.Build();
ITest<TConfig> test = prog;

Просмотреть файл

@ -500,8 +500,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
public void DefaultType()
{
var host = new HostBuilder()
.ConfigureDefaultTestHost<ConfigNullOutParam>()
.AddExtension<ConfigNullOutParam>()
.ConfigureDefaultTestHost<ConfigNullOutParam>(b =>
{
b.AddExtension<ConfigNullOutParam>();
})
.Build();
IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider();
@ -541,8 +543,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
IExtensionConfigProvider ext = prog;
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<TConfig>(appSettings, jobActivator)
.AddExtension(ext)
.ConfigureDefaultTestHost<TConfig>(b =>
{
b.AddExtension(ext);
}, appSettings, jobActivator)
.Build();
ITest<TConfig> test = prog;

Просмотреть файл

@ -49,8 +49,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
var nr = new FakeNameResolver().Add("x", "error");
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<Program>(nr)
.AddExtension<FakeExtClient>()
.ConfigureDefaultTestHost<Program>(b =>
{
b.AddExtension<FakeExtClient>();
}, nameResolver: nr)
.Build();
TestHelpers.AssertIndexingError(() => host.GetJobHost<Program>().Call("Func"), "Program.Func", FakeExtClient.IndexErrorMsg);
@ -67,8 +69,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
var nr = new FakeNameResolver().Add("x", "something");
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<Program>(nr, jobActivator)
.AddExtension<FakeExtClient>()
.ConfigureDefaultTestHost<Program>(b =>
{
b.AddExtension<FakeExtClient>();
}, nr, jobActivator)
.Build();
host.GetJobHost<Program>().Call(nameof(Program.Func));
@ -88,8 +92,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
var nr = new FakeNameResolver().Add("x", "something");
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<Program>(nr, jobActivator)
.AddExtension<FakeExtClient>()
.ConfigureDefaultTestHost<Program>(b =>
{
b.AddExtension<FakeExtClient>();
}, nr, jobActivator)
.Build();
host.GetJobHost<Program>().Call(nameof(Program.FuncNull));

Просмотреть файл

@ -48,8 +48,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
public void TestError()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ErrorProgram>()
.AddExtension<FakeQueueClient>()
.ConfigureDefaultTestHost<ErrorProgram>(b=>
{
b.AddExtension<FakeQueueClient>();
})
.Build();
FakeQueueClient client = host.GetExtension<FakeQueueClient>();
@ -184,8 +186,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
public void Test()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<Functions>()
.AddExtension<FakeQueueClient>()
.ConfigureDefaultTestHost<Functions>(b=>
{
b.AddExtension<FakeQueueClient>();
})
.Build();
JobHost jobHost = host.GetJobHost();

Просмотреть файл

@ -54,8 +54,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
};
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<Functions>()
.AddExtension(client)
.ConfigureDefaultTestHost<Functions>(b =>
{
b.AddExtension(client);
})
.Build();
// With out parameter

Просмотреть файл

@ -168,9 +168,11 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
activator.Add(testInstance);
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<TFunction>()
.ConfigureDefaultTestHost<TFunction>(b=>
{
b.AddExtension<FakeExtClient>();
})
.ConfigureServices(services => services.AddSingleton<IJobActivator>(activator))
.AddExtension<FakeExtClient>()
.Build();
await host.GetJobHost().CallAsync(typeof(TFunction).GetMethod("Func"), arguments);

Просмотреть файл

@ -107,8 +107,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
public async Task TestNoStringTriggerAdapter()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ProgNoString>()
.AddExtension<ExtNoStringConverter>()
.ConfigureDefaultTestHost<ProgNoString>(b =>
{
b.AddExtension<ExtNoStringConverter>();
})
.Build();
var args = new Dictionary<string, object>();
@ -122,9 +124,11 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
public async Task TestTriggerAdapter()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<Prog>()
.AddExtension<FakeQueueClient>()
.AddExtension<Ext>()
.ConfigureDefaultTestHost<Prog>(b =>
{
b.AddExtension<FakeQueueClient>()
.AddExtension<Ext>();
})
.Build();
var args = new Dictionary<string, object>();

Просмотреть файл

@ -313,7 +313,7 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
FakeQueueClient fakeClient = null;
var host = new HostBuilder()
.ConfigureDefaultTestHost<TFunction>(activator: activator)
.ConfigureDefaultTestHost<TFunction>(b=> { }, activator: activator)
.ConfigureServices(services =>
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IExtensionConfigProvider, FakeQueueClient>(p =>

Просмотреть файл

@ -71,9 +71,11 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
nr.Add("appsetting1", "val1");
var host = new HostBuilder()
.ConfigureDefaultTestHost<Functions>()
.ConfigureDefaultTestHost<Functions>(b =>
{
b.AddExtension(client);
})
.ConfigureServices(s => s.AddSingleton<INameResolver>(nr))
.AddExtension(client)
.Build();
host.GetJobHost().Call(typeof(Functions).GetMethod(nameof(Functions.ObjectArray)));
@ -91,9 +93,11 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
var nr = new FakeNameResolver();
nr.Add("appsetting1", "val1");
var host = new HostBuilder()
.ConfigureDefaultTestHost<Functions>()
.ConfigureDefaultTestHost<Functions>(b =>
{
b.AddExtension(client);
})
.ConfigureServices(s => s.AddSingleton<INameResolver>(nr))
.AddExtension(client)
.Build();
host.GetJobHost().Call(typeof(Functions).GetMethod(nameof(Functions.T1)));

Просмотреть файл

@ -91,8 +91,7 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
var nr = new FakeNameResolver().Add("k1", "v1");
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<BadFunction>(nr)
.AddExtension<FakeExtClient>()
.ConfigureDefaultTestHost<BadFunction>(b => { b.AddExtension<FakeExtClient>(); }, nr)
.Build();
TestHelpers.AssertIndexingError(
@ -106,8 +105,7 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
var nr = new FakeNameResolver().Add("k1", "v1");
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<GoodFunction>(nr)
.AddExtension<FakeExtClient>()
.ConfigureDefaultTestHost<GoodFunction>(b => { b.AddExtension<FakeExtClient>(); }, nr)
.Build();
host.GetJobHost<GoodFunction>().Call("Good", new { k2 = "xxxx" });
@ -166,8 +164,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
var nr = new FakeNameResolver().Add("k1", "v1");
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<LocalFunction1>(nr)
.AddExtension<FakeExtClient2>()
.ConfigureDefaultTestHost<LocalFunction1>(b=>
{
b.AddExtension<FakeExtClient2>();
}, nameResolver: nr)
.Build();
host.GetJobHost<LocalFunction1>().Call("NoValidation", new { k2 = "xxxx" }); // Succeeds since validate doesn't run on this rule
@ -180,8 +180,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Common
var nr = new FakeNameResolver().Add("k1", "v1");
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<LocalFunction2>(nr)
.AddExtension<FakeExtClient2>()
.ConfigureDefaultTestHost<LocalFunction2>(b =>
{
b.AddExtension<FakeExtClient2>();
}, nr)
.Build();
TestHelpers.AssertIndexingError(

Просмотреть файл

@ -73,7 +73,7 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Executors
var activator = new FakeActivator(prog);
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<MyProg>(activator: activator)
.ConfigureDefaultTestHost<MyProg>(b=> { }, activator: activator)
.Build();
var task = host.GetJobHost<MyProg>().CallAsync("MyProg.Method");

Просмотреть файл

@ -19,12 +19,15 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Hosting
using (new StartupScope())
{
var builder = new HostBuilder()
.UseWebJobsStartup<TestStartup>();
Assert.True(TestStartup.ConfigureInvoked);
.ConfigureWebJobs(webJobeBuilder =>
{
webJobeBuilder.UseWebJobsStartup<TestStartup>();
});
IHost host = builder.Build();
Assert.True(TestStartup.ConfigureInvoked);
ITestService service = host.Services.GetService<ITestService>();
Assert.NotNull(service);
@ -37,12 +40,16 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Hosting
using (new StartupScope())
{
var builder = new HostBuilder()
.UseWebJobsStartup(typeof(TestStartup));
.ConfigureWebJobs(webJobeBuilder =>
{
webJobeBuilder.UseWebJobsStartup(typeof(TestStartup));
});
Assert.True(TestStartup.ConfigureInvoked);
IHost host = builder.Build();
Assert.True(TestStartup.ConfigureInvoked);
ITestService service = host.Services.GetService<ITestService>();
Assert.NotNull(service);
@ -53,7 +60,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Hosting
public void StartupTypes_FromAttributes_AreConfigured()
{
var builder = new HostBuilder()
.UseExternalStartup(new DefaultStartupTypeDiscoverer(GetType().Assembly));
.ConfigureWebJobs(webJobsBuilder =>
{
webJobsBuilder.UseExternalStartup(new DefaultStartupTypeDiscoverer(GetType().Assembly));
});
IHost host = builder.Build();
@ -82,9 +92,9 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Hosting
public static bool ConfigureInvoked => _configureInvoked;
public void Configure(IHostBuilder builder)
public void Configure(IWebJobsBuilder builder)
{
builder.ConfigureServices(c => c.AddSingleton<ITestService, TestService>());
builder.Services.AddSingleton<ITestService, TestService>();
_configureInvoked = true;
}
@ -98,9 +108,9 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Hosting
public class ExternalTestStartup : IWebJobsStartup
{
public void Configure(IHostBuilder builder)
public void Configure(IWebJobsBuilder builder)
{
builder.ConfigureServices(c => c.AddSingleton<TestExternalService>());
builder.Services.AddSingleton<TestExternalService>();
}
}

Просмотреть файл

@ -24,7 +24,7 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Indexers
var logger = new MyLogger();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<MyProg>(activator: activator)
.ConfigureDefaultTestHost<MyProg>(_ => { }, activator: activator)
.ConfigureServices(services =>
{
services.AddSingleton<IAsyncCollector<FunctionInstanceLogEntry>>(logger);

Просмотреть файл

@ -25,8 +25,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Indexers
var ext = new MyExtension();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<TestProg>()
.AddExtension(ext)
.ConfigureDefaultTestHost<TestProg>(b =>
{
b.AddExtension(ext);
})
.Build();
host.GetJobHost<TestProg>().Call("ImplicitReturn", new { trigger = "trigger" });
@ -39,8 +41,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Indexers
var ext = new MyExtension();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<TestProg>()
.AddExtension(ext)
.ConfigureDefaultTestHost<TestProg>(b =>
{
b.AddExtension(ext);
})
.Build();
host.GetJobHost<TestProg>().Call("ImplicitTaskReturn", new { trigger = "trigger" });
@ -53,8 +57,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Indexers
var ext = new MyExtension();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<TestProg>()
.AddExtension(ext)
.ConfigureDefaultTestHost<TestProg>(b =>
{
b.AddExtension(ext);
})
.Build();
host.GetJobHost<TestProg>().Call("ExplicitReturn");
@ -67,8 +73,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Indexers
var ext = new MyExtension();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<TestProg>()
.AddExtension(ext)
.ConfigureDefaultTestHost<TestProg>(b =>
{
b.AddExtension(ext);
})
.Build();
host.GetJobHost<TestProg>().Call("ExplicitTaskReturn");
@ -81,8 +89,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Indexers
var ext = new MyExtension();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<TestProg>()
.AddExtension(ext)
.ConfigureDefaultTestHost<TestProg>(b=>
{
b.AddExtension(ext);
})
.Build();
host.GetJobHost<TestProg>().Call("ExplicitReturnWins", new { trigger = "trigger" });
@ -95,8 +105,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Indexers
var ext = new MyExtension();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<TestProgErrors>()
.AddExtension(ext)
.ConfigureDefaultTestHost<TestProgErrors>(b =>
{
b.AddExtension(ext);
})
.Build();
TestHelpers.AssertIndexingError(() => host.GetJobHost<TestProgErrors>().Call("Error"), "TestProgErrors.Error",

Просмотреть файл

@ -29,8 +29,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
var ext = new TestExtension();
var host = new HostBuilder()
.ConfigureDefaultTestHost<MyProg>()
.AddExtension(ext)
.ConfigureDefaultTestHost<MyProg>(b =>
{
b.AddExtension(ext);
})
.Build();
IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider();
Assert.Equal(1, ext._counter);
@ -80,8 +82,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
{
var ext = new TestExtension2();
var host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddExtension(ext)
.ConfigureDefaultTestHost(b=>
{
b.AddExtension(ext);
})
.Build();
IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider();
@ -110,8 +114,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
var ext = new TestExtension3();
var host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddExtension(ext)
.ConfigureDefaultTestHost(b =>
{
b.AddExtension(ext);
})
.Build();
IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider();
@ -138,9 +144,11 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
{
var ext = new JArrayTriggerExtension();
var host = new HostBuilder()
.ConfigureDefaultTestHost()
.ConfigureDefaultTestHost(b =>
{
b.AddExtension(ext);
})
.ConfigureTypeLocator() // empty
.AddExtension(ext)
.Build();
IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider();
@ -166,9 +174,11 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
{
var ext = new OpenTypeTriggerExtension();
var host = new HostBuilder()
.ConfigureDefaultTestHost()
.ConfigureDefaultTestHost(b =>
{
b.AddExtension(ext);
})
.ConfigureTypeLocator() // empty
.AddExtension(ext)
.Build();
IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider();

Просмотреть файл

@ -35,12 +35,14 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Loggers
var logger = new MyLogger();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<MyProg>()
.ConfigureDefaultTestHost<MyProg>(b =>
{
b.AddExtension<TestExt>();
})
.ConfigureServices(services =>
{
services.AddSingleton<IAsyncCollector<FunctionInstanceLogEntry>>(logger);
})
.AddExtension<TestExt>()
.Build();
host.GetJobHost<MyProg>().Call("test");
@ -54,12 +56,14 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Loggers
var logger = new MyLogger();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<MyProg>()
.ConfigureDefaultTestHost<MyProg>(b =>
{
b.AddExtension<TestExt>();
})
.ConfigureServices(services =>
{
services.AddSingleton<IAsyncCollector<FunctionInstanceLogEntry>>(logger);
})
.AddExtension<TestExt>()
.Build();
Assert.Throws<FunctionInvocationException>(() => host.GetJobHost<MyProg>().Call("testFailParam"));
@ -73,12 +77,14 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Loggers
var logger = new MyLogger();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<MyProg>()
.ConfigureDefaultTestHost<MyProg>(b =>
{
b.AddExtension<TestExt>();
})
.ConfigureServices(services =>
{
services.AddSingleton<IAsyncCollector<FunctionInstanceLogEntry>>(logger);
})
.AddExtension<TestExt>()
.Build();
Assert.Throws<FunctionInvocationException>(() => host.GetJobHost<MyProg>().Call("testFailBody"));

Просмотреть файл

@ -208,6 +208,8 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
"TriggeredFunctionData",
"TriggerParameterDescriptor",
"ValueBindingContext",
"IWebJobsBuilder",
"WebJobsBuilderExtensions",
"WebJobsExceptionHandler",
"WebJobsHostBuilderExtensions",
"WebJobsServiceCollectionExtensions",

Просмотреть файл

@ -20,8 +20,10 @@ namespace Microsoft.Azure.WebJobs.ServiceBus.UnitTests.Config
public void UseServiceBus_ThrowsArgumentNull_WhenServiceBusConfigIsNull()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddServiceBus()
.ConfigureDefaultTestHost(b =>
{
b.AddServiceBus();
})
.ConfigureServices(s => s.AddSingleton<IOptions<ServiceBusOptions>>(p => null))
.Build();
@ -34,8 +36,10 @@ namespace Microsoft.Azure.WebJobs.ServiceBus.UnitTests.Config
public void UseServiceBus_NoServiceBusConfiguration_PerformsExpectedRegistration()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddServiceBus()
.ConfigureDefaultTestHost(b =>
{
b.AddServiceBus();
})
.Build();
var extensions = host.Services.GetService<IExtensionRegistry>();
@ -56,8 +60,10 @@ namespace Microsoft.Azure.WebJobs.ServiceBus.UnitTests.Config
string fakeConnStr = "test service bus connection";
IHost host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddServiceBus()
.ConfigureDefaultTestHost(b =>
{
b.AddServiceBus();
})
.ConfigureServices(s =>
{
s.Configure<ServiceBusOptions>(o =>

Просмотреть файл

@ -27,9 +27,11 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
var prog = new BindToCloudBlockBlobProgram();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<BindToCloudBlockBlobProgram>(prog)
.AddAzureStorage()
.UseStorage(account)
.ConfigureDefaultTestHost<BindToCloudBlockBlobProgram>(prog, builder =>
{
builder.AddAzureStorage()
.UseStorage(account);
})
.Build();
var jobHost = host.GetJobHost<BindToCloudBlockBlobProgram>();

Просмотреть файл

@ -54,13 +54,15 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
var account = CreateFakeStorageAccount();
var provider = new FakeStorageAccountProvider(account);
var host = new HostBuilder()
.ConfigureDefaultTestHost<BindToCloudBlob2Program>()
.ConfigureDefaultTestHost<BindToCloudBlob2Program>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<IJobActivator>(activator);
services.AddSingleton<StorageAccountProvider>(provider);
})
.AddAzureStorage()
.Build();
// Set the binding data, and verify it's accessible in the function.

Просмотреть файл

@ -27,10 +27,12 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
setTaskSource(src);
var host = new HostBuilder()
.ConfigureDefaultTestHost(programType)
.AddAzureStorage()
.UseStorage(account)
.ConfigureCatchFailures(src, signalOnFirst, ignoreFailureFunctions)
.ConfigureDefaultTestHost(builder =>
{
builder.AddAzureStorage()
.UseStorage(account)
.ConfigureCatchFailures(src, signalOnFirst, ignoreFailureFunctions);
}, programType)
.Build();
try
@ -100,9 +102,11 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
internal static Exception CallFailure(StorageAccount account, Type programType, MethodInfo methodInfo, object arguments)
{
var host = new HostBuilder()
.ConfigureDefaultTestHost(programType)
.AddAzureStorage()
.UseStorage(account)
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage()
.UseStorage(account);
}, programType)
.Build();
var jobHost = host.GetJobHost();
@ -122,10 +126,12 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
internal static void Call(StorageAccount account, Type programType, MethodInfo methodInfo, object arguments, Type[] cloudBlobStreamBinderTypes)
{
var host = new HostBuilder()
.ConfigureDefaultTestHost(programType)
.AddExtension(new CloudBlobStreamAdapterExtension(cloudBlobStreamBinderTypes))
.AddAzureStorage()
.UseStorage(account)
.ConfigureDefaultTestHost(builder =>
{
builder.AddExtension(new CloudBlobStreamAdapterExtension(cloudBlobStreamBinderTypes))
.AddAzureStorage()
.UseStorage(account);
}, programType)
.Build();
var jobHost = host.GetJobHost();
@ -138,9 +144,11 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
setTaskSource(src);
var host = new HostBuilder()
.ConfigureDefaultTestHost(programType)
.AddAzureStorage()
.UseStorage(account)
.ConfigureDefaultTestHost(builder =>
{
builder.AddAzureStorage()
.UseStorage(account);
}, programType)
.Build();
var jobHost = host.GetJobHost();

Просмотреть файл

@ -27,8 +27,11 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Bindings.Data
{
// Arrange
var builder = new HostBuilder()
.ConfigureDefaultTestHost<TestFunctions>()
.UseFakeStorage();
.ConfigureDefaultTestHost<TestFunctions>(b =>
{
b.UseFakeStorage();
});
var host = builder.Build().GetJobHost<TestFunctions>();

Просмотреть файл

@ -39,19 +39,15 @@ namespace Microsoft.Azure.WebJobs
}
// $$$ Rationalize with AddFakeStorageAccountProvider in FunctionTests.
public static IHostBuilder UseFakeStorage(this IHostBuilder builder)
public static IWebJobsBuilder UseFakeStorage(this IWebJobsBuilder builder)
{
return builder.UseStorage(new XFakeStorageAccount());
}
public static IHostBuilder UseStorage(this IHostBuilder builder, StorageAccount account)
public static IWebJobsBuilder UseStorage(this IWebJobsBuilder builder, StorageAccount account)
{
builder
.AddAzureStorage()
.ConfigureServices(services =>
{
services.Add(ServiceDescriptor.Singleton<StorageAccountProvider>(new FakeStorageAccountProvider(account)));
});
builder.AddAzureStorage();
builder.Services.Add(ServiceDescriptor.Singleton<StorageAccountProvider>(new FakeStorageAccountProvider(account)));
return builder;
}

Просмотреть файл

@ -1002,13 +1002,15 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
jobActivator.Add(instance);
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<BindTableEntityToJArrayProgram>()
.ConfigureDefaultTestHost<BindTableEntityToJArrayProgram>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<IJobActivator>(jobActivator);
services.AddSingleton<StorageAccountProvider>(new FakeStorageAccountProvider(account));
})
.AddAzureStorage()
.Build();
// Act
@ -1076,12 +1078,14 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
// Act
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<BindTableEntityToJObjectProgram>()
.ConfigureDefaultTestHost<BindTableEntityToJObjectProgram>(b =>
{
b.AddAzureStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<StorageAccountProvider>(new FakeStorageAccountProvider(account));
})
.AddAzureStorage()
.Build();
var prog = host.GetJobHost<BindTableEntityToJObjectProgram>();

Просмотреть файл

@ -29,7 +29,6 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests
"Microsoft.Azure.WebJobs",
"Microsoft.Azure.WebJobs.Host",
"Microsoft.Extensions.DependencyInjection.Abstractions",
"Microsoft.Extensions.Hosting.Abstractions",
"Microsoft.Extensions.Logging.Abstractions",
"Microsoft.Extensions.Options",
"Microsoft.WindowsAzure.Storage",

Просмотреть файл

@ -17,11 +17,13 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
{
[Fact]
public void Queue_IfNameIsInvalid_ThrowsDuringIndexing()
{
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<InvalidQueueNameProgram>()
.AddAzureStorage()
.UseFakeStorage()
.ConfigureDefaultTestHost<InvalidQueueNameProgram>(b =>
{
b.AddAzureStorage()
.UseFakeStorage();
})
.Build();

Просмотреть файл

@ -27,9 +27,11 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
var prog = new InstanceProgram();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<InstanceProgram>(prog)
.AddAzureStorage()
.UseStorage(account)
.ConfigureDefaultTestHost<InstanceProgram>(prog, builder =>
{
builder.AddAzureStorage()
.UseStorage(account);
})
.Build();
// Act
@ -61,9 +63,11 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
var prog = new InstanceAsyncProgram();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<InstanceAsyncProgram>(prog)
.AddAzureStorage()
.UseStorage(account)
.ConfigureDefaultTestHost<InstanceAsyncProgram>(prog, builder =>
{
builder.AddAzureStorage()
.UseStorage(account);
})
.Build();
// Act
@ -95,8 +99,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
await account.AddQueueMessageAsync(expectedMessage, QueueName);
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<DisposeInstanceProgram>()
.UseStorage(account)
.ConfigureDefaultTestHost<DisposeInstanceProgram>(builder =>
{
builder.UseStorage(account);
})
.Build();
// Act & Assert
@ -139,8 +145,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
await account.AddQueueMessageAsync(message, QueueName);
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<InstanceCustomActivatorProgram>(null, activator)
.UseStorage(account)
.ConfigureDefaultTestHost<InstanceCustomActivatorProgram>(builder =>
{
builder.UseStorage(account);
}, null, activator)
.Build();
// Act

Просмотреть файл

@ -319,8 +319,10 @@ namespace Microsoft.Azure.WebJobs.Host.UnitTests.Queues
{
// Create a default host to get some default services
IHost host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddAzureStorage()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage();
})
.Build();
var storageAccount = host.GetStorageAccount();

Просмотреть файл

@ -190,8 +190,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
public TestFixture()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost()
.AddAzureStorage()
.ConfigureDefaultTestHost(b =>
{
b.AddAzureStorage();
})
.Build();
var accountProvider = host.Services.GetService<StorageAccountProvider>();

Просмотреть файл

@ -38,8 +38,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
{
var account = CreateFakeStorageAccount();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<GenericProgram<ICollector<string>>>()
.UseStorage(account)
.ConfigureDefaultTestHost<GenericProgram<ICollector<string>>>(b =>
{
b.UseStorage(account);
})
.Build();
host.GetJobHost().Call<GenericProgram<ICollector<string>>>("Func");
@ -68,8 +70,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
public void Catch_Bad_Name_At_IndexTime()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ProgramWithStaticBadName>()
.AddAzureStorage()
.ConfigureDefaultTestHost<ProgramWithStaticBadName>(builder =>
{
builder.AddAzureStorage();
})
.Build();
string errorMessage = GetErrorMessageForBadQueueName(ProgramWithStaticBadName.BadQueueName, "name");
@ -100,8 +104,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
{
var nameResolver = new FakeNameResolver().Add("key", "1");
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ProgramWithVariableQueueName>()
.UseFakeStorage()
.ConfigureDefaultTestHost<ProgramWithVariableQueueName>(builder =>
{
builder.UseFakeStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<INameResolver>(nameResolver);
@ -131,8 +137,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
var nameResolver = new FakeNameResolver().Add("key", "$"); // Illegal
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ProgramWithVariableQueueName>()
.UseFakeStorage()
.ConfigureDefaultTestHost<ProgramWithVariableQueueName>(builder =>
{
builder.UseFakeStorage();
})
.ConfigureServices(services =>
{
services.AddSingleton<INameResolver>(nameResolver);
@ -177,8 +185,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
var account = CreateFakeStorageAccount();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ProgramWithTriggerAndBindingData>()
.UseStorage(account)
.ConfigureDefaultTestHost<ProgramWithTriggerAndBindingData>(b =>
{
b.UseStorage(account);
})
.Build();
var trigger = new ProgramWithTriggerAndBindingData.Poco { xyz = "abc" };
@ -236,8 +246,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
var account = CreateFakeStorageAccount();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ProgramWithTriggerAndCompoundBindingData>()
.UseStorage(account)
.ConfigureDefaultTestHost<ProgramWithTriggerAndCompoundBindingData>(b =>
{
b.UseStorage(account);
})
.Build();
var trigger = new ProgramWithTriggerAndCompoundBindingData.Poco
@ -347,8 +359,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
// Verify that indexing fails if the [Queue] trigger needs binding data that's not present.
var account = CreateFakeStorageAccount();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ProgramBadContract>()
.UseStorage(account)
.ConfigureDefaultTestHost<ProgramBadContract>(b =>
{
b.UseStorage(account);
})
.Build();
TestHelpers.AssertIndexingError(() => host.GetJobHost().Call<ProgramBadContract>("Func"),
@ -369,8 +383,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
{
var account = CreateFakeStorageAccount();
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<ProgramCantBindToObject>()
.UseStorage(account)
.ConfigureDefaultTestHost<ProgramCantBindToObject>(b =>
{
b.UseStorage(account);
})
.Build();
TestHelpers.AssertIndexingError(() => host.GetJobHost().Call<ProgramCantBindToObject>("Func"),
@ -399,8 +415,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
private void Fails_Cant_Bind_To_Types_Worker<T>(string typeName)
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<GenericProgram<T>>()
.UseFakeStorage()
.ConfigureDefaultTestHost<GenericProgram<T>>(b =>
{
b.UseFakeStorage();
})
.Build();
TestHelpers.AssertIndexingError(() => host.GetJobHost().Call<GenericProgram<T>>("Func"),

Просмотреть файл

@ -33,8 +33,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<TProgram>()
.UseFakeStorage()
.ConfigureDefaultTestHost<TProgram>(builder =>
{
builder.UseFakeStorage();
})
.Build();
host.GetJobHost<TProgram>().AssertIndexingError(methodName, expectedErrorMessage);
@ -64,9 +66,11 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
public async Task Table_SingleOut_Supported()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<BindToSingleOutProgram>()
.AddAzureStorage()
.UseFakeStorage()
.ConfigureDefaultTestHost<BindToSingleOutProgram>(builder =>
{
builder.AddAzureStorage()
.UseFakeStorage();
})
.Build();
host.GetJobHost<BindToSingleOutProgram>().Call(nameof(BindToSingleOutProgram.Run));
@ -92,9 +96,11 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
public async Task Table_ResolvedName()
{
IHost host = new HostBuilder()
.ConfigureDefaultTestHost<BindToICollectorITableEntityResolvedTableProgram>()
.AddAzureStorage()
.UseFakeStorage()
.ConfigureDefaultTestHost<BindToICollectorITableEntityResolvedTableProgram>(builder =>
{
builder.AddAzureStorage()
.UseFakeStorage();
})
.Build();
host.GetJobHost<BindToICollectorITableEntityResolvedTableProgram>().Call("Run", new { t1 = "ZZ" });
@ -120,11 +126,12 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
var ext = new TableConverter();
var host = new HostBuilder()
.ConfigureDefaultTestHost<CustomTableBindingExtensionProgram>()
.AddExtension(ext)
.AddAzureStorage()
.UseFakeStorage()
.Build();
.ConfigureDefaultTestHost<CustomTableBindingExtensionProgram>(builder =>
{
builder.AddExtension(ext)
.UseFakeStorage();
})
.Build();
host.GetJobHost<CustomTableBindingExtensionProgram>().Call("Run"); // Act
@ -198,8 +205,10 @@ namespace Microsoft.Azure.WebJobs.Host.FunctionalTests
// Act
var host = new HostBuilder()
.ConfigureDefaultTestHost<BindToICollectorJObjectProgramKeysInAttr>()
.UseFakeStorage()
.ConfigureDefaultTestHost<BindToICollectorJObjectProgramKeysInAttr>(builder =>
{
builder.UseFakeStorage();
})
.Build();
host.GetJobHost<BindToICollectorJObjectProgramKeysInAttr>().Call("Run");