| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 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
- /// <summary>
- /// Current ApplicationContext
- /// </summary>
- private static ApplicationContext _current;
- /// <summary>
- /// Returns the current ApplicationContext or creates one if doesn't exist already
- /// </summary>
- public static ApplicationContext Current
- {
- get
- {
- if (_current == null)
- {
- _current = new ApplicationContext();
- }
- return _current;
- }
- }
- #endregion
- #region Fields
- /// <summary>
- /// Returns the application wide app container builder
- /// </summary>
- private static IContainer _appContainer;
- /// <summary>
- /// Returns the application wide controller container builder
- /// </summary>
- private static IContainer _controllerContainer;
- #endregion
- #region Services
- /// <summary>
- /// Returns the generel DbContextService
- /// </summary>
- public DbContextService DbContextService { get; set; }
- #endregion
- #region Ctor
- /// <summary>
- /// Initializes a new instance of the ApplicationContext class
- /// </summary>
- public ApplicationContext()
- {
- DbContextService = new DbContextService(_appContainer.Resolve<IDbContext>());
- }
- #endregion
- #region Initialization
- /// <summary>
- /// Registers all service ressources needed by the ApplicationContext
- /// </summary>
- public static void InitServices()
- {
- var appBuilder = new ContainerBuilder();
- appBuilder
- .RegisterInstance(new AppendixObjectContext("Server=localhost\\SQLEXPRESS;Database=Nachtragsmanagement;User Id=nachtragdat;Password=nachtragdat;"))
- .As<IDbContext>()
- .SingleInstance();
- appBuilder
- .RegisterType<DbRelationService>()
- .As<IDbRelationService>();
- appBuilder
- .RegisterControllers(Assembly.GetCallingAssembly());
- _appContainer = appBuilder.Build();
- DependencyResolver.SetResolver(new AutofacDependencyResolver(_appContainer));
- }
- #endregion
- }
- }
|