-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.cs
60 lines (50 loc) · 2.46 KB
/
Module.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
using Microsoft.Practices.Unity;
using System;
using VirtoCommerce.CustomerModule.Data.Model;
using VirtoCommerce.CustomerModule.Data.Repositories;
using VirtoCommerce.CustomerModule.Data.Services;
using VirtoCommerce.Domain.Customer.Model;
using VirtoCommerce.OrderBot.Services.Core.Models;
using VirtoCommerce.OrderBot.Services.Data.Models;
using VirtoCommerce.OrderBot.Services.Data.Repositories;
using VirtoCommerce.OrderBot.Services.Data.Services;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Modularity;
using VirtoCommerce.Platform.Data.Infrastructure;
using VirtoCommerce.Platform.Data.Infrastructure.Interceptors;
namespace VirtoCommerce.OrderBot.Services.Web
{
public class Module : ModuleBase
{
private readonly string _connectionString = ConfigurationHelper.GetConnectionStringValue("VirtoCommerce.OrderBot.Services") ?? ConfigurationHelper.GetConnectionStringValue("VirtoCommerce");
private readonly IUnityContainer _container;
public Module(IUnityContainer container)
{
_container = container;
}
public override void SetupDatabase()
{
base.SetupDatabase();
using (var db = new BotContactRepository(_connectionString, _container.Resolve<AuditableInterceptor>()))
{
var initializer = new SetupDatabaseInitializer<BotContactRepository, Data.Migrations.Configuration>();
initializer.InitializeDatabase(db);
}
}
public override void Initialize()
{
base.Initialize();
BotContactRepository BotContactRepository() => new BotContactRepository(_connectionString, _container.Resolve<AuditableInterceptor>(), new EntityPrimaryKeyGeneratorInterceptor());
_container.RegisterInstance<Func<ICustomerRepository>>(BotContactRepository);
_container.RegisterInstance<Func<IMemberRepository>>(BotContactRepository);
_container.RegisterType<CommerceMembersServiceImpl, BotContactMembersService>();
}
public override void PostInitialize()
{
base.PostInitialize();
AbstractTypeFactory<Member>.OverrideType<Contact, BotContact>().MapToType<BotContactEntity>();
AbstractTypeFactory<MemberDataEntity>.OverrideType<ContactDataEntity, BotContactEntity>();
AbstractTypeFactory<MembersSearchCriteria>.OverrideType<MembersSearchCriteria, BotContactSearchCriteria>();
}
}
}