Esempio n. 1
0
        public TestBase()
        {
            // direct access to the db
            //db = new SqlConnection(ConnectionString);
            scope = new TransactionScope();

            var builder = new ContainerBuilder();

            // builder.RegisterModule(new TModule());
            AutoFacServiceConfig.RegisterServices(builder);
            DataAccessServiceConfig.RegisterServices(builder);

            builder.Register(c => new SqlConnection(ConnectionString)).As <IDbConnection>().InstancePerLifetimeScope();

            container = builder.Build();
        }
        public static void Register()
        {
            // Get your HttpConfiguration.
            var config = GlobalConfiguration.Configuration;

            // Create your builder.
            var builder = new ContainerBuilder();

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            // OPTIONAL: Register the Autofac filter provider.
            builder.RegisterWebApiFilterProvider(config);

            AutoFacServiceConfig.RegisterServices(builder);
            DataAccessServiceConfig.RegisterServices(builder);
            builder.Register(c => new SqlConnection(ConnectionString)).As <IDbConnection>().InstancePerLifetimeScope();

            // Set the dependency resolver to be Autofac.
            Container = builder.Build();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(Container);
        }