Esempio n. 1
0
        public void Instance_Get2Instances_ReturnsSameInstances()
        {
            TextFileLogger.CreateInstance("test");

            var instance1 = TextFileLogger.GetInstance();
            var instance2 = TextFileLogger.GetInstance();

            Assert.AreSame(instance1, instance2);
            instance1.TestField++;
            Assert.AreEqual(instance1.TestField, instance2.TestField);
            instance2.TestField++;
            Assert.AreEqual(instance1.TestField, instance2.TestField);
        }
Esempio n. 2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ContainerBuilder builder = new ContainerBuilder();
            var config = GlobalConfiguration.Configuration;

            builder.RegisterType <CardRepository>().As <IRepository <Card> >();
            builder.RegisterType <UserRepository>().As <IRepository <User> >();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            var path = Server.MapPath("/test_log.txt");

            TextFileLogger.CreateInstance(path);
            builder.RegisterInstance(TextFileLogger.GetInstance()).As <ILogger>();
            IContainer container = builder.Build();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }