mirror of https://github.com/abpframework/abp.git
7 changed files with 95 additions and 53 deletions
@ -1,29 +1,33 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Docs.Documents |
|||
{ |
|||
public class DocumentStoreFactory : IDocumentStoreFactory, ITransientDependency |
|||
{ |
|||
private readonly IServiceProvider _serviceProvider; |
|||
protected DocumentStoreOptions Options { get; } |
|||
protected IServiceProvider ServiceProvider { get; } |
|||
|
|||
public DocumentStoreFactory(IServiceProvider serviceProvider) |
|||
public DocumentStoreFactory( |
|||
IServiceProvider serviceProvider, |
|||
IOptions<DocumentStoreOptions> options) |
|||
{ |
|||
_serviceProvider = serviceProvider; |
|||
Options = options.Value; |
|||
ServiceProvider = serviceProvider; |
|||
} |
|||
|
|||
public virtual IDocumentStore Create(string documentStoreType) |
|||
public virtual IDocumentStore Create(string storeType) |
|||
{ |
|||
//TODO: Should be extensible
|
|||
|
|||
switch (documentStoreType) |
|||
var serviceType = Options.Stores.GetOrDefault(storeType); |
|||
if (serviceType == null) |
|||
{ |
|||
case GithubDocumentStore.Type: |
|||
return _serviceProvider.GetRequiredService<GithubDocumentStore>(); |
|||
default: |
|||
throw new ApplicationException($"Undefined document store: {documentStoreType}"); |
|||
throw new ApplicationException($"Undefined document store: {storeType}"); |
|||
} |
|||
|
|||
return (IDocumentStore) ServiceProvider.GetRequiredService(serviceType); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Docs.Documents |
|||
{ |
|||
public class DocumentStoreOptions |
|||
{ |
|||
public Dictionary<string, Type> Stores { get; set; } |
|||
|
|||
public DocumentStoreOptions() |
|||
{ |
|||
Stores = new Dictionary<string, Type>(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,28 +0,0 @@ |
|||
using System; |
|||
using Volo.Docs.Projects; |
|||
|
|||
namespace Volo.Docs.Documents |
|||
{ |
|||
public static class ProjectGithubExtensions |
|||
{ |
|||
public static string GetGithubUrl(this Projects.Project project) |
|||
{ |
|||
CheckGithubProject(project); |
|||
return project.ExtraProperties["GithubRootUrl"] as string; |
|||
} |
|||
|
|||
public static void SetGithubUrl(this Projects.Project project, string value) |
|||
{ |
|||
CheckGithubProject(project); |
|||
project.ExtraProperties["GithubRootUrl"] = value; |
|||
} |
|||
|
|||
private static void CheckGithubProject(Project project) |
|||
{ |
|||
if (project.DocumentStoreType != GithubDocumentStore.Type) |
|||
{ |
|||
throw new ApplicationException("Given project has not a Github document store!"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp; |
|||
using Volo.Docs.GitHub.Documents; |
|||
using Volo.Docs.Projects; |
|||
|
|||
namespace Volo.Docs.GitHub.Projects |
|||
{ |
|||
public static class ProjectGithubExtensions |
|||
{ |
|||
public static string GetGitHubUrl([NotNull] this Project project) |
|||
{ |
|||
CheckGitHubProject(project); |
|||
return project.ExtraProperties["GitHubRootUrl"] as string; |
|||
} |
|||
|
|||
public static void SetGitHubUrl([NotNull] this Project project, string value) |
|||
{ |
|||
CheckGitHubProject(project); |
|||
project.ExtraProperties["GitHubRootUrl"] = value; |
|||
} |
|||
|
|||
public static string GetGitHubAccessTokenOrNull([NotNull] this Project project) |
|||
{ |
|||
CheckGitHubProject(project); |
|||
return project.ExtraProperties["GitHubAccessToken"] as string; |
|||
} |
|||
|
|||
public static void SetGitHubAccessToken([NotNull] this Project project, string value) |
|||
{ |
|||
CheckGitHubProject(project); |
|||
project.ExtraProperties["GitHubAccessToken"] = value; |
|||
} |
|||
|
|||
private static void CheckGitHubProject(Project project) |
|||
{ |
|||
Check.NotNull(project, nameof(project)); |
|||
|
|||
if (project.DocumentStoreType != GithubDocumentStore.Type) |
|||
{ |
|||
throw new ApplicationException("Given project has not a Github document store!"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue