-
Notifications
You must be signed in to change notification settings - Fork 4
/
RegistrationClass.cs
69 lines (60 loc) · 2.61 KB
/
RegistrationClass.cs
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// <copyright file="RegistrationClass.cs" company="Mobilize.Net">
// Copyright (c) 2018 Mobilize, Inc. All Rights Reserved,
// All classes are provided for customer use only,
// all other use is prohibited without prior written consent from Mobilize.Net,
// no warranty express or implied,
// use at own risk.
// </copyright>
namespace WebSite
{
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Mobilize.WebMap.Common.Core;
using Mobilize.WebMap.Common.Core.ObservableWrapper;
using Mobilize.WebMap.Common.Messaging;
using Mobilize.WebMap.Core.ObservableWrapper;
using Mobilize.WebMap.Messaging;
/// <summary>
/// Registration for Wrappers and Mappers
/// </summary>
[Mobilize.WebMap.Common.Attributes.ExcludeObservableWrapperTracking]
public static class RegistrationClass
{
private static List<Assembly> assembliesForRegistrations = AssemblyRegistration.GetAssembliesForRegistration(Assembly.GetEntryAssembly());
/// <summary>
/// Registers the model projectors.
/// </summary>
/// <param name="services">The services.</param>
public static void RegisterModelMappers(this IServiceCollection services)
{
services.AddSingleton<IMapperCatalog>((provider) =>
{
var logger = provider.GetService<ILoggerFactory>();
var service = new MapperCatalog(logger);
// register mappers from Assemblies for registration (it includes current Assembly)
AssemblyRegistration.RegisterMappers(assembliesForRegistrations, logger.CreateLogger("Information"), service);
return service;
});
}
/// <summary>
/// Registers the wrappers.
/// </summary>
/// <param name="services">The services.</param>
public static void RegisterWrappers(this IServiceCollection services)
{
services.AddSingleton<IObservableWrapperCatalog>(
(provider) =>
{
var catalog = new ObservableWrapperCatalog();
// register wrappers from referenced Assemblies
AssemblyRegistration.RegisterWrappers(assembliesForRegistrations, catalog);
// assembliesForRegistrations is not longer required, so is cleared out.
assembliesForRegistrations.Clear();
assembliesForRegistrations = null;
return catalog;
});
}
}
}