using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.Extensions.DependencyInjection; using System.Threading.Tasks; using Oqtane.Services; using System.Reflection; using System; using System.Linq; using System.Net.Http; using Oqtane.Modules; using Oqtane.Shared; using Oqtane.Providers; using Microsoft.AspNetCore.Components.Authorization; namespace Oqtane.Client { public class Program { public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("app"); builder.Services.AddSingleton( new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) } ); builder.Services.AddOptions(); // register auth services builder.Services.AddAuthorizationCore(); builder.Services.AddScoped(); builder.Services.AddScoped(s => s.GetRequiredService()); // register scoped core services builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); // dynamically register module contexts and repository services Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { Type[] implementationtypes = assembly.GetTypes() .Where(item => item.GetInterfaces().Contains(typeof(IService))) .ToArray(); foreach (Type implementationtype in implementationtypes) { Type servicetype = Type.GetType(implementationtype.AssemblyQualifiedName.Replace(implementationtype.Name, "I" + implementationtype.Name)); if (servicetype != null) { builder.Services.AddScoped(servicetype, implementationtype); // traditional service interface } else { builder.Services.AddScoped(implementationtype, implementationtype); // no interface defined for service } } } await builder.Build().RunAsync(); } } }