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
        static void Main(string[] args)
        {
            var container       = AutofacSetup.ConfigureDependencies();
            var gameEnvironment = container.Resolve <IGameEnvironment>();

            gameEnvironment.StartGame();
        }
Ejemplo n.º 3
0
        protected void Application_Start()
        {
            AutoMapperConfig.ConfigureAutoMapper();
            AutofacSetup.ConfigureAutofac();

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Ejemplo n.º 4
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            var ioc = new AutofacSetup();

            _container = ioc.Init();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        }
Ejemplo n.º 5
0
        private static void ConfigureDependencyInjection()
        {
            ContainerBuilder builder = new ContainerBuilder();

            //var config = new HubConfiguration();

            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            //builder.RegisterHubs(Assembly.GetExecutingAssembly());

            IContainer container = AutofacSetup.ConfigureDependencies(builder);

            //GlobalHost.DependencyResolver = new Autofac.Integration.SignalR.AutofacDependencyResolver(container);
        }
Ejemplo n.º 6
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);
    }
        public void ResolveController_UsingSqlData_ExpectPatientsControllerWithPatientsContext()
        {
            // arrange
            var ioc = new AutofacSetup();

            var expectedContext = typeof(PatientContext);

            // act
            var container = ioc.Init();

            var actualContext = container.Resolve <IPatientContext>();

            // assert
            Assert.IsInstanceOf(expectedContext, actualContext);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            // Register instances
            _serviceProvider = AutofacSetup.RegisterServices(_serviceProvider);


            // Get starting point
            var calculate = _serviceProvider.GetService <ICalculate>();

            try
            {
                bool run = true;
                while (run)
                {
                    run = calculate.Execute();

                    // Rerun until press esc
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("Press ESC to exit or any other key to continue.");
                    if (Console.ReadKey().Key == ConsoleKey.Escape)
                    {
                        run = false;
                    }
                }
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;

                var isCustomError = e.GetType().GetInterface("IApplicationException") != null;
                if (isCustomError)
                {
                    Console.WriteLine(e.Message);
                }
                else
                {
                    Log.Error(e, e.StackTrace);
                    Console.WriteLine("An unexpected error occured please refer to your Administrator.");
                }
            }

            AutofacSetup.DisposeServices(_serviceProvider);
        }
        public void Get_PatientDoesNotExist_ThrowsHttpResponseExceptionHttpStatusCodeNotFound()
        {
            // arrange
            var ioc = new AutofacSetup();

            var useInMemoryDataContext = true;

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            var container = ioc.Init(useInMemoryDataContext);

            var controller = container.Resolve <PatientsController>();

            var patientId = 2;

            // act
            Action action = () => controller.Get(patientId);

            // assert
            action.ShouldThrowExactly <HttpResponseException>(HttpStatusCode.NotFound.ToString());
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            _serviceProvider = AutofacSetup.RegisterServices(_serviceProvider);

            var calculateTempratures = _serviceProvider.GetService <ICalculateTempratures>();

            try
            {
                var result = calculateTempratures.Execute();
            }
            catch (Exception e)
            {
                // todo: It should be written in a log file and keep continue to program based on exception type.
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine(e.Message.ToString());
                Console.WriteLine("Please restart the program.");
            }

            Console.ReadKey();
            AutofacSetup.DisposeServices(_serviceProvider);
        }
        public void Get_PatientExistsWithAnEpisode_ExpectPatientWithEpisode()
        {
            // arrange
            var ioc = new AutofacSetup();

            var useInMemoryDataContext = true;

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            var container = ioc.Init(useInMemoryDataContext);

            var controller = container.Resolve <PatientsController>();

            var patientId = 1;

            var expected = new Patient
            {
                DateOfBirth = new DateTime(1972, 10, 27),
                FirstName   = "Millicent",
                PatientId   = patientId,
                LastName    = "Hammond",
                NhsNumber   = "1111111111",
                Episodes    = new[]
                {
                    new Episode
                    {
                        AdmissionDate = new DateTime(2014, 11, 12),
                        Diagnosis     = "Irritation of inner ear",
                        DischargeDate = new DateTime(2014, 11, 27),
                        EpisodeId     = 1,
                        PatientId     = patientId
                    }
                }
            };

            // act
            var patient = controller.Get(patientId);

            // assert
            patient.ShouldBeEquivalentTo(expected);
        }
Ejemplo n.º 12
0
        public void Configuration(IAppBuilder app)
        {
            ConfigureOAuth(app);
            AutomapperConfiguration.Configure();
            Mapper.AssertConfigurationIsValid();
            var builder = new ContainerBuilder();

            HttpConfiguration config = new HttpConfiguration();

            config.Filters.Add(new AuthorizeAttribute());
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            WebApiConfig.Register(config);


            AutofacSetup.RegisterDependencies(ref builder);
            var container = builder.Build();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);
            app.UseWebApi(config);
        }