Replace NotNullAttribute with thrown exceptions

This commit is contained in:
Pranav K 2015-10-08 17:23:53 -07:00
parent ba2bb3f0c9
commit 72d63e2613
6 changed files with 60 additions and 15 deletions

View File

@ -4,7 +4,6 @@
using System;
using Microsoft.AspNet.Diagnostics.Elm;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.OptionsModel;
@ -15,8 +14,13 @@ namespace Microsoft.AspNet.Builder
/// <summary>
/// Enables the Elm logging service, which can be accessed via the <see cref="ElmPageMiddleware"/>.
/// </summary>
public static IApplicationBuilder UseElmCapture([NotNull] this IApplicationBuilder builder)
public static IApplicationBuilder UseElmCapture(this IApplicationBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
// add the elm provider to the factory here so the logger can start capturing logs immediately
var factory = builder.ApplicationServices.GetRequiredService<ILoggerFactory>();
var store = builder.ApplicationServices.GetRequiredService<ElmStore>();
@ -29,8 +33,13 @@ namespace Microsoft.AspNet.Builder
/// <summary>
/// Enables viewing logs captured by the <see cref="ElmCaptureMiddleware"/>.
/// </summary>
public static IApplicationBuilder UseElmPage([NotNull] this IApplicationBuilder builder)
public static IApplicationBuilder UseElmPage(this IApplicationBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
return builder.UseMiddleware<ElmPageMiddleware>();
}
}

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNet.Diagnostics.Elm
@ -12,8 +11,18 @@ namespace Microsoft.AspNet.Diagnostics.Elm
private readonly ElmStore _store;
private readonly ElmOptions _options;
public ElmLoggerProvider([NotNull] ElmStore store, [NotNull] ElmOptions options)
public ElmLoggerProvider(ElmStore store, ElmOptions options)
{
if (store == null)
{
throw new ArgumentNullException(nameof(store));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
_store = store;
_options = options;
}

View File

@ -5,7 +5,6 @@ using System.Runtime.Remoting.Messaging;
#else
using System.Threading;
#endif
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNet.Diagnostics.Elm
{
@ -61,8 +60,18 @@ namespace Microsoft.AspNet.Diagnostics.Elm
}
#endif
public static IDisposable Push([NotNull] ElmScope scope, [NotNull] ElmStore store)
public static IDisposable Push(ElmScope scope, ElmStore store)
{
if (scope == null)
{
throw new ArgumentNullException(nameof(scope));
}
if (store == null)
{
throw new ArgumentNullException(nameof(store));
}
var temp = Current;
Current = scope;
Current.Parent = temp;

View File

@ -3,7 +3,6 @@
using System;
using Microsoft.AspNet.Diagnostics.Elm;
using Microsoft.Extensions.Internal;
namespace Microsoft.Extensions.DependencyInjection
{
@ -12,8 +11,13 @@ namespace Microsoft.Extensions.DependencyInjection
/// <summary>
/// Registers an <see cref="ElmStore"/> and configures default <see cref="ElmOptions"/>.
/// </summary>
public static IServiceCollection AddElm([NotNull] this IServiceCollection services)
public static IServiceCollection AddElm(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
services.AddOptions();
services.AddSingleton<ElmStore>();
return services;
@ -25,9 +29,19 @@ namespace Microsoft.Extensions.DependencyInjection
/// <param name="services">The services available in the application.</param>
/// <param name="configureOptions">The <see cref="ElmOptions"/> which need to be configured.</param>
public static void ConfigureElm(
[NotNull] this IServiceCollection services,
[NotNull] Action<ElmOptions> configureOptions)
this IServiceCollection services,
Action<ElmOptions> configureOptions)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
if (configureOptions == null)
{
throw new ArgumentNullException(nameof(configureOptions));
}
services.Configure(configureOptions);
}
}

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNet.Diagnostics.Elm
{
@ -34,8 +34,13 @@ namespace Microsoft.AspNet.Diagnostics.Elm
/// Adds a new <see cref="ActivityContext"/> to the store.
/// </summary>
/// <param name="context">The context to be added to the store.</param>
public void AddActivity([NotNull] ActivityContext activity)
public void AddActivity(ActivityContext activity)
{
if (activity == null)
{
throw new ArgumentNullException(nameof(activity));
}
lock (Activities)
{
Activities.AddLast(activity);

View File

@ -7,8 +7,7 @@
},
"dependencies": {
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*",
"Microsoft.Extensions.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" }
"Microsoft.Extensions.Logging.Abstractions": "1.0.0-*"
},
"frameworks": {