Ejemplo n.º 1
0
        public override void Configuration(IAppBuilder app)
        {
            var httpConfig = new HttpConfiguration();
            // this now returns ContainerBuilder instead of the container
            var builder = AutofacSetup.Register(httpConfig)
                          // register your mock, change this to whatever lifetime scope you need
                          var moqAirportCollection = new AirportCollection();

            moqAirportCollection.Airports = new List <Airport> {
                new Airport {
                    IATA = "moq", Name = "moqName"
                }
            };
            var mock = AutoMock.GetLoose()
                       var moqObj = MockObj = mock.Mock <IAirportService>()
                                              .Setup(x => x.GetAirports())
                                              .Returns(moqAirportCollection);

            builder.Register <IAirportService>(() => moqObj);


            container = builder.Build();
            WebApiConfig.Register(httpConfig);


            appBuilder.UseAutofacMiddleware(container);
            appBuilder.UseAutofacWebApi(httpConfig);
            appBuilder.UseWebApi(httpConfig);
        }
Ejemplo n.º 2
0
    // make this virtual
    public virtual void Configuration(IAppBuilder appBuilder)
    {
        var httpConfig = new HttpConfiguration();
        // have this return the ContainerBuilder instead of the container
        var builder = AutofacSetup.Register(httpConfig)
                      container = builder.Build();

        WebApiConfig.Register(httpConfig);


        appBuilder.UseAutofacMiddleware(container);
        appBuilder.UseAutofacWebApi(httpConfig);
        appBuilder.UseWebApi(httpConfig);
    }