using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Web.Mvc; using Autofac; using Autofac.Integration.Mvc; using GreenTree.Nachtragsmanagement.Data; using GreenTree.Nachtragsmanagement.Services.DbContext; using GreenTree.Nachtragsmanagement.Services.Test; namespace GreenTree.Nachtragsmanagement.Web.Framework { public class ApplicationContext { #region Statics /// /// Current ApplicationContext /// private static ApplicationContext _current; /// /// Returns the current ApplicationContext or creates one if doesn't exist already /// public static ApplicationContext Current { get { if (_current == null) { _current = new ApplicationContext(); } return _current; } } #endregion #region Fields /// /// Returns the application wide app container builder /// private static IContainer _appContainer; /// /// Returns the application wide controller container builder /// private static IContainer _controllerContainer; #endregion #region Services /// /// Returns the generel DbContextService /// public DbContextService DbContextService { get; set; } #endregion #region Ctor /// /// Initializes a new instance of the ApplicationContext class /// public ApplicationContext() { DbContextService = new DbContextService(_appContainer.Resolve()); } #endregion #region Initialization /// /// Registers all service ressources needed by the ApplicationContext /// public static void InitServices() { var appBuilder = new ContainerBuilder(); appBuilder .RegisterInstance(new AppendixObjectContext("Server=localhost\\SQLEXPRESS;Database=Nachtragsmanagement;User Id=nachtragdat;Password=nachtragdat;")) .As() .SingleInstance(); appBuilder .RegisterType() .As(); appBuilder .RegisterControllers(Assembly.GetCallingAssembly()); _appContainer = appBuilder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(_appContainer)); } #endregion } }