Skip to content

Commit

Permalink
Merge pull request #1238 from DuendeSoftware/brock/nullable-types
Browse files Browse the repository at this point in the history
configure nullable types for some public APIs
  • Loading branch information
brockallen committed Apr 11, 2023
2 parents 3c10811 + d451e01 commit b6da8a9
Show file tree
Hide file tree
Showing 203 changed files with 785 additions and 527 deletions.
7 changes: 6 additions & 1 deletion src/AspNetIdentity/IdentityServerBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using System;
using System.Linq;
Expand Down Expand Up @@ -119,12 +120,16 @@ internal static void AddDecorator<TService>(this IServiceCollection services)
return new DisposableDecorator<TService>((TService)registration.ImplementationFactory(provider));
}, registration.Lifetime));
}
else
else if (registration.ImplementationType != null)
{
var type = registration.ImplementationType;
var innerType = typeof(Decorator<,>).MakeGenericType(typeof(TService), registration.ImplementationType);
services.Add(new ServiceDescriptor(typeof(Decorator<TService>), innerType, ServiceLifetime.Transient));
services.Add(new ServiceDescriptor(type, type, registration.Lifetime));
}
else
{
throw new InvalidOperationException("Invalid registration in DI for: " + typeof(TService).Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using System;
using Duende.IdentityServer.EntityFramework.DbContexts;
Expand All @@ -23,7 +24,7 @@ public static class IdentityServerEntityFrameworkBuilderExtensions
/// <param name="storeOptionsAction">The store options action.</param>
/// <returns></returns>
public static IServiceCollection AddConfigurationDbContext(this IServiceCollection services,
Action<ConfigurationStoreOptions> storeOptionsAction = null)
Action<ConfigurationStoreOptions>? storeOptionsAction = null)
{
return services.AddConfigurationDbContext<ConfigurationDbContext>(storeOptionsAction);
}
Expand All @@ -36,7 +37,7 @@ public static class IdentityServerEntityFrameworkBuilderExtensions
/// <param name="storeOptionsAction">The store options action.</param>
/// <returns></returns>
public static IServiceCollection AddConfigurationDbContext<TContext>(this IServiceCollection services,
Action<ConfigurationStoreOptions> storeOptionsAction = null)
Action<ConfigurationStoreOptions>? storeOptionsAction = null)
where TContext : DbContext, IConfigurationDbContext
{
var options = new ConfigurationStoreOptions();
Expand Down Expand Up @@ -97,7 +98,7 @@ public static class IdentityServerEntityFrameworkBuilderExtensions
/// <param name="storeOptionsAction">The store options action.</param>
/// <returns></returns>
public static IServiceCollection AddOperationalDbContext(this IServiceCollection services,
Action<OperationalStoreOptions> storeOptionsAction = null)
Action<OperationalStoreOptions>? storeOptionsAction = null)
{
return services.AddOperationalDbContext<PersistedGrantDbContext>(storeOptionsAction);
}
Expand All @@ -110,7 +111,7 @@ public static class IdentityServerEntityFrameworkBuilderExtensions
/// <param name="storeOptionsAction">The store options action.</param>
/// <returns></returns>
public static IServiceCollection AddOperationalDbContext<TContext>(this IServiceCollection services,
Action<OperationalStoreOptions> storeOptionsAction = null)
Action<OperationalStoreOptions>? storeOptionsAction = null)
where TContext : DbContext, IPersistedGrantDbContext
{
var storeOptions = new OperationalStoreOptions();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using Duende.IdentityServer.EntityFramework.Interfaces;
using Microsoft.EntityFrameworkCore;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using Duende.IdentityServer.EntityFramework.Entities;
using Duende.IdentityServer.EntityFramework.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using System;
using Duende.IdentityServer.EntityFramework.Entities;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using System;
using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using System;
using Microsoft.EntityFrameworkCore;
Expand All @@ -18,23 +19,23 @@ public class ConfigurationStoreOptions
/// <value>
/// The configure database context.
/// </value>
public Action<DbContextOptionsBuilder> ConfigureDbContext { get; set; }
public Action<DbContextOptionsBuilder>? ConfigureDbContext { get; set; }

/// <summary>
/// Callback in DI resolve the EF DbContextOptions. If set, ConfigureDbContext will not be used.
/// </summary>
/// <value>
/// The configure database context.
/// </value>
public Action<IServiceProvider, DbContextOptionsBuilder> ResolveDbContextOptions { get; set; }
public Action<IServiceProvider, DbContextOptionsBuilder>? ResolveDbContextOptions { get; set; }

/// <summary>
/// Gets or sets the default schema.
/// </summary>
/// <value>
/// The default schema.
/// </value>
public string DefaultSchema { get; set; } = null;
public string? DefaultSchema { get; set; } = null;

/// <summary>
/// Gets or sets the identity resource table configuration.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using System;
using Microsoft.EntityFrameworkCore;
Expand All @@ -18,23 +19,23 @@ public class OperationalStoreOptions
/// <value>
/// The configure database context.
/// </value>
public Action<DbContextOptionsBuilder> ConfigureDbContext { get; set; }
public Action<DbContextOptionsBuilder>? ConfigureDbContext { get; set; }

/// <summary>
/// Callback in DI resolve the EF DbContextOptions. If set, ConfigureDbContext will not be used.
/// </summary>
/// <value>
/// The configure database context.
/// </value>
public Action<IServiceProvider, DbContextOptionsBuilder> ResolveDbContextOptions { get; set; }
public Action<IServiceProvider, DbContextOptionsBuilder>? ResolveDbContextOptions { get; set; }

/// <summary>
/// Gets or sets the default schema.
/// </summary>
/// <value>
/// The default schema.
/// </value>
public string DefaultSchema { get; set; } = null;
public string? DefaultSchema { get; set; } = null;

/// <summary>
/// Gets or sets the persisted grants table configuration.
Expand Down
5 changes: 3 additions & 2 deletions src/EntityFramework.Storage/Options/TableConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

namespace Duende.IdentityServer.EntityFramework.Options;

Expand Down Expand Up @@ -43,5 +44,5 @@ public TableConfiguration(string name, string schema)
/// <value>
/// The schema.
/// </value>
public string Schema { get; set; }
public string? Schema { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using System.Collections.Generic;
using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using System.Threading;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using System;
using Duende.IdentityServer.EntityFramework;
Expand Down Expand Up @@ -28,7 +29,7 @@ public static class IdentityServerEntityFrameworkBuilderExtensions
/// <returns></returns>
public static IIdentityServerBuilder AddConfigurationStore(
this IIdentityServerBuilder builder,
Action<ConfigurationStoreOptions> storeOptionsAction = null)
Action<ConfigurationStoreOptions>? storeOptionsAction = null)
{
return builder.AddConfigurationStore<ConfigurationDbContext>(storeOptionsAction);
}
Expand All @@ -42,7 +43,7 @@ public static class IdentityServerEntityFrameworkBuilderExtensions
/// <returns></returns>
public static IIdentityServerBuilder AddConfigurationStore<TContext>(
this IIdentityServerBuilder builder,
Action<ConfigurationStoreOptions> storeOptionsAction = null)
Action<ConfigurationStoreOptions>? storeOptionsAction = null)
where TContext : DbContext, IConfigurationDbContext
{
builder.Services.AddConfigurationDbContext<TContext>(storeOptionsAction);
Expand Down Expand Up @@ -82,7 +83,7 @@ public static class IdentityServerEntityFrameworkBuilderExtensions
/// <returns></returns>
public static IIdentityServerBuilder AddOperationalStore(
this IIdentityServerBuilder builder,
Action<OperationalStoreOptions> storeOptionsAction = null)
Action<OperationalStoreOptions>? storeOptionsAction = null)
{
return builder.AddOperationalStore<PersistedGrantDbContext>(storeOptionsAction);
}
Expand All @@ -96,7 +97,7 @@ public static class IdentityServerEntityFrameworkBuilderExtensions
/// <returns></returns>
public static IIdentityServerBuilder AddOperationalStore<TContext>(
this IIdentityServerBuilder builder,
Action<OperationalStoreOptions> storeOptionsAction = null)
Action<OperationalStoreOptions>? storeOptionsAction = null)
where TContext : DbContext, IPersistedGrantDbContext
{
builder.Services.AddOperationalDbContext<TContext>(storeOptionsAction);
Expand Down
7 changes: 4 additions & 3 deletions src/IdentityServer/Configuration/CryptoHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using IdentityModel;
using Microsoft.IdentityModel.Tokens;
Expand Down Expand Up @@ -114,7 +115,7 @@ internal static ECCurve GetCurveFromCrvValue(string crv)
/// <summary>
/// Returns the matching curve name for signing algorithm.
/// </summary>
internal static string GetCurveNameFromSigningAlgorithm(string alg)
internal static string? GetCurveNameFromSigningAlgorithm(string alg)
{
return alg switch
{
Expand Down Expand Up @@ -185,9 +186,9 @@ internal static string GetECDsaSigningAlgorithmValue(IdentityServerConstants.ECD
};
}

internal static X509Certificate2 FindCertificate(string name, StoreLocation location, NameType nameType)
internal static X509Certificate2? FindCertificate(string name, StoreLocation location, NameType nameType)
{
X509Certificate2 certificate = null;
X509Certificate2? certificate = null;

if (location == StoreLocation.LocalMachine)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using Duende.IdentityServer.ResponseHandling;
using Duende.IdentityServer.Services;
Expand Down Expand Up @@ -406,7 +407,7 @@ public static IIdentityServerBuilder AddBackChannelLogoutService<T>(this IIdenti
/// <param name="builder">The builder.</param>
/// <param name="configureClient">The configuration callback.</param>
/// <returns></returns>
public static IHttpClientBuilder AddBackChannelLogoutHttpClient(this IIdentityServerBuilder builder, Action<HttpClient> configureClient = null)
public static IHttpClientBuilder AddBackChannelLogoutHttpClient(this IIdentityServerBuilder builder, Action<HttpClient>? configureClient = null)
{
const string name = IdentityServerConstants.HttpClients.BackChannelLogoutHttpClient;
IHttpClientBuilder httpBuilder;
Expand Down Expand Up @@ -443,7 +444,7 @@ public static IHttpClientBuilder AddBackChannelLogoutHttpClient(this IIdentitySe
/// <param name="builder">The builder.</param>
/// <param name="configureClient">The configuration callback.</param>
/// <returns></returns>
public static IHttpClientBuilder AddJwtRequestUriHttpClient(this IIdentityServerBuilder builder, Action<HttpClient> configureClient = null)
public static IHttpClientBuilder AddJwtRequestUriHttpClient(this IIdentityServerBuilder builder, Action<HttpClient>? configureClient = null)
{
const string name = IdentityServerConstants.HttpClients.JwtRequestUriHttpClient;
IHttpClientBuilder httpBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using Duende.IdentityServer;
using Duende.IdentityServer.Configuration;
Expand Down Expand Up @@ -390,12 +391,16 @@ internal static void AddDecorator<TService>(this IServiceCollection services)
return new DisposableDecorator<TService>((TService)registration.ImplementationFactory(provider));
}, registration.Lifetime));
}
else
else if (registration.ImplementationType != null)
{
var type = registration.ImplementationType;
var innerType = typeof(Decorator<,>).MakeGenericType(typeof(TService), registration.ImplementationType);
services.Add(new ServiceDescriptor(typeof(Decorator<TService>), innerType, ServiceLifetime.Transient));
services.Add(new ServiceDescriptor(type, type, registration.Lifetime));
}
else
{
throw new InvalidOperationException("Invalid registration in DI for: " + typeof(TService).Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using Duende.IdentityServer;
using Duende.IdentityServer.Configuration;
Expand Down Expand Up @@ -161,7 +162,7 @@ public static IIdentityServerBuilder AddSigningCredential(this IIdentityServerBu
public static IIdentityServerBuilder AddDeveloperSigningCredential(
this IIdentityServerBuilder builder,
bool persistKey = true,
string filename = null,
string? filename = null,
IdentityServerConstants.RsaSigningAlgorithm signingAlgorithm = IdentityServerConstants.RsaSigningAlgorithm.RS256)
{
if (filename == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using Duende.IdentityServer.Models;
using Duende.IdentityServer.Services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using Duende.IdentityServer.Configuration;
using Duende.IdentityServer.Services;
Expand Down Expand Up @@ -77,7 +78,8 @@ public static IIdentityServerBuilder AddServerSideSessionStore<T>(this IIdentity
{
builder.Services.AddTransient<IServerSideSessionStore>(svcs =>
{
if (svcs.GetService<IServerSideSessionsMarker>() == null) return null;
// odd that this Func is marked as non-null return value, since it is allowed to return null here.
if (svcs.GetService<IServerSideSessionsMarker>() == null) return null!;
return svcs.GetRequiredService<T>();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

namespace Microsoft.Extensions.DependencyInjection;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

#nullable enable

using Microsoft.Extensions.DependencyInjection;
using System;
Expand Down
Loading

0 comments on commit b6da8a9

Please sign in to comment.