1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Web;
- using Autofac;
- using Autofac.Integration.Mvc;
- namespace EMIS.Utility
- {
- public interface IAutofacContainerProvider
- {
- IContainer Container { get; set; }
- }
- public class AutofacHelper
- {
- private static IContainer _Container;
- public static IContainer Container
- {
- get
- {
- if (_Container == null)
- {
- if (CreateContainerFun != null)
- {
- _Container = CreateContainerFun();
- }
- else
- {
- _Container = (HttpContext.Current.ApplicationInstance as IAutofacContainerProvider).Container;
- }
- }
- return _Container;
- }
- set
- {
- _Container = value;
- }
- }
- public static Func<IContainer> CreateContainerFun { get; set; }
- public static ILifetimeScope RequestLifetimeScope
- {
- get
- {
- return
- Container.BeginLifetimeScope(System.Web.HttpContext.Current != null
- ? System.Web.HttpContext.Current.Timestamp
- : DateTime.Now);
- }
- }
- }
- }
|