songjun
2024-09-04 cc908053e0b5075fbfd27350b6da4b39bca9e550
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.Entity;
using PalGain.Core;
using PalGain.Core.Tasks;
using Autofac;
using Autofac.Integration.Mvc;
using Autofac.Configuration;
using sbcLabSystem.Data;
using sbcLabSystem.Service.Account;
using sbcLabSystem.Service.QC;
using sbcLabSystem.Service.Task;
 
namespace sbcLabSystem.Framework
{
    public class DependencyRegistrar : IDependencyRegistrar
    {
        public void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            //HTTP context and other related stuff
            builder.Register(c =>
                (new HttpContextWrapper(HttpContext.Current) as HttpContextBase))
                .As<HttpContextBase>()
                .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve<HttpContextBase>().Request)
                .As<HttpRequestBase>()
                .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve<HttpContextBase>().Response)
                .As<HttpResponseBase>()
                .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve<HttpContextBase>().Server)
                .As<HttpServerUtilityBase>()
                .InstancePerLifetimeScope();
            builder.Register(c => c.Resolve<HttpContextBase>().Session)
                .As<HttpSessionStateBase>()
                .InstancePerLifetimeScope();
 
            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());
            builder.Register<IDbContext>(c => 
                new sbcLabSystem.Data.DBContext.FreseniusDBContext()).InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRespository<>)).InstancePerLifetimeScope();
            //cache manager 
            builder.RegisterType<MemoryCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_static").SingleInstance();
            //web helper  
            builder.RegisterType<WebHelper>().As<IWebHelper>().InstancePerLifetimeScope();
            //services
            builder.RegisterType<AccountService>().InstancePerLifetimeScope();
            builder.RegisterType<ScheduleTaskService>().As<IScheduleTaskService>().InstancePerLifetimeScope();
            builder.RegisterType<QCService>().InstancePerLifetimeScope();
        }   
 
        public int Order
        {
            get { return 0; }
        }
    }
}