Skip to content

Commit

Permalink
Adding all default services to the service container
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewc committed Oct 21, 2015
1 parent ddf2acf commit 5ba3a16
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/Dashboard/app/controllers/ConsoleOutputController.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
$scope.consoleText = ' ';
}

// TODO: do this in a more angular-y way - do not manipulate DOM directly from a controller
$timeout(function() {
textArea.scrollTop(textArea[0].scrollHeight);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public static IReadOnlyDictionary<string, string> ConvertParameters(IReadOnlyDic
/// <returns>Path compatible string representation of the given parameter or null if its type is not supported.</returns>
public static string ConvertParameterValueToString(object parameterValue)
{
// TODO: Consider unifying with TToStringConverterFactory, though that selects a fixed
// converter at indexing time and this waits until invocation time to decide how to convert.
if (parameterValue != null)
{
switch (Type.GetTypeCode(parameterValue.GetType()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ private Type[] FindTypes(Assembly assembly, IEnumerable<Assembly> extensionAssem
}
catch (ReflectionTypeLoadException ex)
{
// TODO: Log this somewhere?
_log.WriteLine("Warning: Only got partial types from assembly: {0}", assembly.FullName);
_log.WriteLine("Exception message: {0}", ex.ToString());

Expand All @@ -130,7 +129,6 @@ private Type[] FindTypes(Assembly assembly, IEnumerable<Assembly> extensionAssem
}
catch (Exception ex)
{
// TODO: Log this somewhere?
_log.WriteLine("Warning: Failed to get types from assembly: {0}", assembly.FullName);
_log.WriteLine("Exception message: {0}", ex.ToString());
}
Expand Down
33 changes: 18 additions & 15 deletions src/Microsoft.Azure.WebJobs.Host/JobHostConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public sealed class JobHostConfiguration : IServiceProvider
private string _serviceBusConnectionString;

private string _hostId;
private ITypeLocator _typeLocator;
private INameResolver _nameResolver = new DefaultNameResolver();
private IJobActivator _activator = DefaultJobActivator.Instance;

/// <summary>
/// Initializes a new instance of the <see cref="JobHostConfiguration"/> class.
Expand All @@ -56,14 +53,17 @@ public JobHostConfiguration(string dashboardAndStorageConnectionString)
{
_storageAccountProvider = new DefaultStorageAccountProvider(this);
}

IExtensionRegistry extensions = new DefaultExtensionRegistry();
_typeLocator = new DefaultTypeLocator(ConsoleProvider.Out, extensions);

Singleton = new SingletonConfiguration();

// add our built in services here
IExtensionRegistry extensions = new DefaultExtensionRegistry();
ITypeLocator typeLocator = new DefaultTypeLocator(ConsoleProvider.Out, extensions);
AddService<IExtensionRegistry>(extensions);
AddService<StorageClientFactory>(new StorageClientFactory());
AddService<INameResolver>(new DefaultNameResolver());
AddService<IJobActivator>(DefaultJobActivator.Instance);
AddService<ITypeLocator>(typeLocator);
}

/// <summary>Gets or sets the host ID.</summary>
Expand Down Expand Up @@ -107,16 +107,15 @@ public IJobActivator JobActivator
{
get
{
return _activator;
return GetService<IJobActivator>();
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}

_activator = value;
AddService<IJobActivator>(value);
}
}

Expand Down Expand Up @@ -164,15 +163,17 @@ public string ServiceBusConnectionString
/// <summary>Gets or sets the type locator.</summary>
public ITypeLocator TypeLocator
{
get { return _typeLocator; }
get
{
return GetService<ITypeLocator>();
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}

_typeLocator = value;
AddService<ITypeLocator>(value);
}
}

Expand All @@ -181,15 +182,17 @@ public ITypeLocator TypeLocator
/// </summary>
public INameResolver NameResolver
{
get { return _nameResolver; }
get
{
return GetService<INameResolver>();
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}

_nameResolver = value;
AddService<INameResolver>(value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.Linq;
using Microsoft.Azure.WebJobs.Host.Executors;
using Microsoft.Azure.WebJobs.Host.Indexers;
using Microsoft.Azure.WebJobs.Host.TestCommon;
using Xunit;

Expand Down Expand Up @@ -142,7 +143,7 @@ public void JobActivator_IfNull_Throws()
}

[Fact]
public void GetService_ReturnsExpectedDefaultServices()
public void GetService_IExtensionRegistry_ReturnsDefaultRegistry()
{
JobHostConfiguration configuration = new JobHostConfiguration();

Expand All @@ -154,9 +155,21 @@ public void GetService_ReturnsExpectedDefaultServices()
Assert.NotNull(extensionRegistry);
IComparable[] results = extensionRegistry.GetExtensions<IComparable>().ToArray();
Assert.Equal(3, results.Length);
}

[Theory]
[InlineData(typeof(IJobHostContextFactory), typeof(JobHostContextFactory))]
[InlineData(typeof(IExtensionRegistry), typeof(DefaultExtensionRegistry))]
[InlineData(typeof(ITypeLocator), typeof(DefaultTypeLocator))]
[InlineData(typeof(StorageClientFactory), typeof(StorageClientFactory))]
[InlineData(typeof(INameResolver), typeof(DefaultNameResolver))]
[InlineData(typeof(IJobActivator), typeof(DefaultJobActivator))]
public void GetService_ReturnsExpectedDefaultServices(Type serviceType, Type expectedInstanceType)
{
JobHostConfiguration configuration = new JobHostConfiguration();

IJobHostContextFactory jobHostContextFactory = configuration.GetService<IJobHostContextFactory>();
Assert.NotNull(jobHostContextFactory);
var service = configuration.GetService(serviceType);
Assert.Equal(expectedInstanceType, service.GetType());
}

[Fact]
Expand Down

0 comments on commit 5ba3a16

Please sign in to comment.