Add null checks

This commit is contained in:
Hisham Bin Ateya
2020-01-03 20:35:55 +03:00
parent 2fdc01644e
commit 675b2a9110
2 changed files with 27 additions and 1 deletions

View File

@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
@ -8,6 +9,11 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static IMvcBuilder AddOqtaneApplicationParts(this IMvcBuilder mvcBuilder)
{
if (mvcBuilder is null)
{
throw new ArgumentNullException(nameof(mvcBuilder));
}
// load MVC application parts from module assemblies
foreach (var assembly in OqtaneServiceCollectionExtensions.GetOqtaneModuleAssemblies())
{

View File

@ -20,6 +20,11 @@ namespace Microsoft.Extensions.DependencyInjection
public static IServiceCollection AddOqtaneModules(this IServiceCollection services)
{
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}
LoadAssemblies("Module");
return services;
@ -27,6 +32,11 @@ namespace Microsoft.Extensions.DependencyInjection
public static IServiceCollection AddOqtaneThemes(this IServiceCollection services)
{
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}
LoadAssemblies("Theme");
return services;
@ -34,6 +44,11 @@ namespace Microsoft.Extensions.DependencyInjection
public static IServiceCollection AddOqtaneServices(this IServiceCollection services)
{
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}
// dynamically register module services, contexts, and repository classes
var assemblies = Assemblies.
Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Module.")).ToArray();
@ -52,6 +67,11 @@ namespace Microsoft.Extensions.DependencyInjection
public static IServiceCollection AddOqtaneHostedServices(this IServiceCollection services)
{
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}
// dynamically register hosted services
var hostedServiceType = typeof(IHostedService);
foreach (var assembly in Assemblies)