Merge pull request #463 from chlupac/IClientStartup
IClientStartup implementation
This commit is contained in:
80
Oqtane.Shared/Extensions/AssemblyExtensions.cs
Normal file
80
Oqtane.Shared/Extensions/AssemblyExtensions.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Oqtane.Services;
|
||||
using Oqtane.Shared;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace System.Reflection
|
||||
{
|
||||
public static class AssemblyExtensions
|
||||
{
|
||||
public static IEnumerable<Type> GetInterfaces<TInterfaceType>(this Assembly assembly)
|
||||
{
|
||||
if (assembly is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assembly));
|
||||
}
|
||||
|
||||
return assembly.GetTypes(typeof(TInterfaceType));
|
||||
}
|
||||
|
||||
public static IEnumerable<Type> GetTypes(this Assembly assembly, Type interfaceType)
|
||||
{
|
||||
if (assembly is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assembly));
|
||||
}
|
||||
|
||||
if (interfaceType is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(interfaceType));
|
||||
}
|
||||
|
||||
return assembly.GetTypes()
|
||||
//.Where(t => t.GetInterfaces().Contains(interfaceType));
|
||||
.Where(x => interfaceType.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract);
|
||||
}
|
||||
|
||||
public static IEnumerable<Type> GetTypes<T>(this Assembly assembly)
|
||||
{
|
||||
return assembly.GetTypes(typeof(T));
|
||||
}
|
||||
|
||||
public static IEnumerable<T> GetInstances<T>(this Assembly assembly) where T : class
|
||||
{
|
||||
if (assembly is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assembly));
|
||||
}
|
||||
var type = typeof(T);
|
||||
var list = assembly.GetTypes()
|
||||
.Where(x => type.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract && !x.IsGenericType);
|
||||
|
||||
foreach (var type1 in list)
|
||||
{
|
||||
if (Activator.CreateInstance(type1) is T instance) yield return instance;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsOqtaneAssembly(this Assembly assembly)
|
||||
{
|
||||
return assembly.FullName != null && (assembly.FullName.Contains("oqtane", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public static bool IsOqtaneAssembly(this FileInfo fileInfo)
|
||||
{
|
||||
return (fileInfo.Name.Contains("oqtane", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public static IEnumerable<Assembly> GetOqtaneAssemblies(this AppDomain appDomain)
|
||||
{
|
||||
return appDomain.GetAssemblies().Where(a => a.IsOqtaneAssembly());
|
||||
}
|
||||
public static IEnumerable<Assembly> GetOqtaneClientAssemblies(this AppDomain appDomain)
|
||||
{
|
||||
return appDomain.GetOqtaneAssemblies()
|
||||
.Where(a => a.GetTypes<IClientStartup>().Any());
|
||||
}
|
||||
}
|
||||
}
|
11
Oqtane.Shared/Interfaces/IClientStartup.cs
Normal file
11
Oqtane.Shared/Interfaces/IClientStartup.cs
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
public interface IClientStartup
|
||||
{
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
void ConfigureServices(IServiceCollection services);
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.2" />
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="4.7.1" />
|
||||
</ItemGroup>
|
||||
|
Reference in New Issue
Block a user