| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autofac;
- using Autofac.Integration.Mvc;
- using GreenTree.Nachtragsmanagement.Data;
- using GreenTree.Nachtragsmanagement.Services.DbContext;
- 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 container builder
- /// </summary>
- private static IContainer _appContainer;
- #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 ressources needed by the ApplicationContext
- /// </summary>
- public static void Init()
- {
- var appBuilder = new ContainerBuilder();
- appBuilder
- .RegisterInstance(new AppendixObjectContext("Server=localhost\\SQLEXPRESS;Database=Nachtragsmanagement;User Id=nachtragdat;Password=nachtragdat;"))
- .As<IDbContext>()
- .SingleInstance();
- _appContainer = appBuilder.Build();
- }
- #endregion
- }
- }
|