diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlOptions.cs b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlOptions.cs new file mode 100644 index 0000000000..e46bac2c66 --- /dev/null +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlOptions.cs @@ -0,0 +1,14 @@ +using Volo.Abp.Ui.Navigation.Urls; + +namespace Volo.Abp.Ui.Navigation.Urls +{ + public class AppUrlOptions + { + public ApplicationUrlDictionary Applications { get; } + + public AppUrlOptions() + { + Applications = new ApplicationUrlDictionary(); + } + } +} diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs new file mode 100644 index 0000000000..f55b741579 --- /dev/null +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Ui.Navigation.Urls +{ + public class AppUrlProvider : IAppUrlProvider, ITransientDependency + { + protected AppUrlOptions Options { get; } + + public AppUrlProvider(IOptions options) + { + Options = options.Value; + } + + public virtual string GetUrl(string appName, string urlName = null) + { + var app = Options.Applications[appName]; + + if (urlName.IsNullOrEmpty()) + { + if (app.RootUrl.IsNullOrEmpty()) + { + throw new AbpException($"RootUrl for the application '{appName}' was not configured. Use {nameof(AppUrlOptions)} to configure it!"); + } + + return app.RootUrl; + } + + var url = app.Urls.GetOrDefault(urlName); + if (url.IsNullOrEmpty()) + { + throw new AbpException($"Url, named '{urlName}', for the application '{appName}' was not configured. Use {nameof(AppUrlOptions)} to configure it!"); + } + + if (app.RootUrl == null) + { + return url; + } + + return app.RootUrl.EnsureEndsWith('/') + url; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/ApplicationUrlDictionary.cs b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/ApplicationUrlDictionary.cs new file mode 100644 index 0000000000..d299d885ea --- /dev/null +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/ApplicationUrlDictionary.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; + +namespace Volo.Abp.Ui.Navigation.Urls +{ + public class ApplicationUrlDictionary + { + private readonly IDictionary _applications; + + public ApplicationUrlInfo this[string appName] + { + get + { + if (!_applications.ContainsKey(appName)) + { + _applications[appName] = new ApplicationUrlInfo(); + } + + return _applications[appName]; + } + } + + public ApplicationUrlDictionary() + { + _applications = new Dictionary(); + } + } +} diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/ApplicationUrlInfo.cs b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/ApplicationUrlInfo.cs new file mode 100644 index 0000000000..644a6f99d1 --- /dev/null +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/ApplicationUrlInfo.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace Volo.Abp.Ui.Navigation.Urls +{ + public class ApplicationUrlInfo + { + public string RootUrl { get; set; } + + public IDictionary Urls { get; } + + public ApplicationUrlInfo() + { + Urls = new Dictionary(); + } + } +} diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/IAppUrlProvider.cs b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/IAppUrlProvider.cs new file mode 100644 index 0000000000..ac7ce1abd5 --- /dev/null +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/IAppUrlProvider.cs @@ -0,0 +1,9 @@ +using JetBrains.Annotations; + +namespace Volo.Abp.Ui.Navigation.Urls +{ + public interface IAppUrlProvider + { + string GetUrl([NotNull] string appName, [CanBeNull] string urlName = null); + } +}