private static IContainer GetAutofacContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            builder.Register(
                c => {
                var connectionString = ConfigurationManager.ConnectionStrings["TheAppConnectionString"].ConnectionString;
                return(new TheAppDbConnection(connectionString));
            })
            .As <TheAppDbConnection>()
            .InstancePerLifetimeScope()
            .ExternallyOwned();

            builder.Register(
                c =>
            {
                var theAppDbConnection = c.Resolve <TheAppDbConnection>();
                return(TheAppModels.FactoryMethod(theAppDbConnection));
            })
            .InstancePerDependency();

            builder.Register <HttpSessionStateBase>(c => new HttpSessionStateWrapper(HttpContext.Current.Session))
            .InstancePerDependency();

            builder.Register <HttpContextBase>(c => new HttpContextWrapper(HttpContext.Current))
            .InstancePerLifetimeScope();

            builder.RegisterType <UnitOfWork>().As <IUnitOfWork>().InstancePerLifetimeScope();
            builder.RegisterType <UnitOfWorkService>().InstancePerLifetimeScope();
            builder.RegisterType <PupilNativeService>().As <IPupilService>().InstancePerLifetimeScope();

            return(builder.Build());
        }
        public PupilServiceDbTest() : base(_theAppDbConnection.Connection)
        {
            var theAppModels = TheAppModels.FactoryMethod(_theAppDbConnection);

            _unitOfWork = new UnitOfWork(theAppModels);

            _pupilService = new PupilORMService(_unitOfWork);
        }
Exemplo n.º 3
0
 public PupilRepository(TheAppModels context) : base(context)
 {
 }