Added AppUrlOptions

pull/7950/head
Halil ibrahim Kalkan 6 years ago
parent a53d36d7fa
commit e36eeeb1dd

@ -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();
}
}
}

@ -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<AppUrlOptions> 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;
}
}
}

@ -0,0 +1,27 @@
using System.Collections.Generic;
namespace Volo.Abp.Ui.Navigation.Urls
{
public class ApplicationUrlDictionary
{
private readonly IDictionary<string, ApplicationUrlInfo> _applications;
public ApplicationUrlInfo this[string appName]
{
get
{
if (!_applications.ContainsKey(appName))
{
_applications[appName] = new ApplicationUrlInfo();
}
return _applications[appName];
}
}
public ApplicationUrlDictionary()
{
_applications = new Dictionary<string, ApplicationUrlInfo>();
}
}
}

@ -0,0 +1,16 @@
using System.Collections.Generic;
namespace Volo.Abp.Ui.Navigation.Urls
{
public class ApplicationUrlInfo
{
public string RootUrl { get; set; }
public IDictionary<string, string> Urls { get; }
public ApplicationUrlInfo()
{
Urls = new Dictionary<string, string>();
}
}
}

@ -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);
}
}
Loading…
Cancel
Save