You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
798 B
28 lines
798 B
using Masa.Blazor.Pro.Global;
|
|
using Masa.Blazor.Pro.Global.Nav.Model;
|
|
using System.Text.Json;
|
|
|
|
namespace Microsoft.Extensions.DependencyInjection;
|
|
|
|
public static class NavServiceCollectionExtensions
|
|
{
|
|
public static IServiceCollection AddNav(this IServiceCollection services, List<NavModel> navList)
|
|
{
|
|
services.AddSingleton(navList);
|
|
services.AddScoped<NavHelper>();
|
|
|
|
return services;
|
|
}
|
|
|
|
public static IServiceCollection AddNav(this IServiceCollection services, string navSettingsFile)
|
|
{
|
|
var navList = JsonSerializer.Deserialize<List<NavModel>>(File.ReadAllText(navSettingsFile));
|
|
|
|
if (navList is null) throw new Exception("Please configure the navigation first!");
|
|
|
|
services.AddNav(navList);
|
|
|
|
return services;
|
|
}
|
|
}
|
|
|
|
|