generated from Kentico/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDependencyInjection.cs
More file actions
40 lines (31 loc) · 1.38 KB
/
DependencyInjection.cs
File metadata and controls
40 lines (31 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using XperienceCommunity.DataRepository.Interfaces;
using XperienceCommunity.DataRepository.Models;
namespace XperienceCommunity.DataRepository;
public static class DependencyInjection
{
/// <summary>
/// Adds Xperience data repositories to the service collection.
/// </summary>
/// <param name="services">The service collection to add the repositories to.</param>
/// <param name="options">A delegate to configure the repository options.</param>
/// <returns>The updated service collection.</returns>
public static IServiceCollection AddXperienceDataRepositories(this IServiceCollection services, Action<RepositoryOptions>? options)
{
var repositoryOptions = new RepositoryOptions() { CacheMinutes = 60 };
if (options != null)
{
options(repositoryOptions);
services.Configure(options);
}
else
{
services.Configure<RepositoryOptions>(config => config.CacheMinutes = 60);
}
services.TryAddScoped(typeof(IContentRepository<>), typeof(ContentTypeRepository<>));
services.TryAddScoped(typeof(IPageRepository<>), typeof(PageTypeRepository<>));
services.TryAddScoped<IMediaFileRepository, MediaFileRepository>();
return services;
}
}