Example #1
0
        private static void TestUnityIntegration()
        {
            var forceFieldConfiguration = new Configuration();

            forceFieldConfiguration.Add <CachingAdvice>(ApplyAdvice.OnEveryMethod);
            forceFieldConfiguration.Add <ExceptionHandlingAdvice>(new ApplyAdviceOnAllRepositories());
            forceFieldConfiguration.Add <LoggerAdvice>(new ApplyAdviceOnAllRepositories());
            forceFieldConfiguration.Add <EmptyAdvice>(ApplyAdvice.OnEveryMethod);

            var unity = new ForceFieldUnityContainer(forceFieldConfiguration);

            unity.RegisterType <ICacheProvider, RamCacheProvider>();
            unity.RegisterType <ILoggingService, LoggingService>();
            unity.RegisterType <IOtherService, OtherService>();
            unity.RegisterType <ICacheConfigurationService, ExampleOfCacheConfigurationService>();
            unity.RegisterType <IPersonRepository, PersonRepository>();

            var repository = unity.Resolve <IPersonRepository>();

            repository.Save(new Person {
                Key = 1, Age = 25, Name = "John"
            });
            repository.GetByName("John");
            repository.GetByName("John");

            var service       = unity.Resolve <IOtherService>();
            var meaningOfLife = service.Bar();
        }
Example #2
0
 private ForceFieldUnityContainer CreateContainer()
 {
     var unityAdvisorConfiguration = new Configuration();
     unityAdvisorConfiguration.Add<TestAdvice>(ApplyAdvice.OnEveryMethod);
     var forceFieldUnityContainer = new ForceFieldUnityContainer(unityAdvisorConfiguration);
     forceFieldUnityContainer.RegisterType<ITestInterface, TestInterfaceExtended>();
     return forceFieldUnityContainer;
 }
Example #3
0
        private ForceFieldUnityContainer CreateContainer()
        {
            var unityAdvisorConfiguration = new Configuration();

            unityAdvisorConfiguration.Add <TestAdvice>(ApplyAdvice.OnEveryMethod);
            var forceFieldUnityContainer = new ForceFieldUnityContainer(unityAdvisorConfiguration);

            forceFieldUnityContainer.RegisterType <ITestInterface, TestInterfaceExtended>();
            return(forceFieldUnityContainer);
        }
        public void AllAdvicesShouldBeAutomaticlyRegistered()
        {
            //Arrange
            var configuration = new Configuration();
            configuration.Add<TestAdvice>(ApplyAdvice.OnEveryMethod);
            var container = new ForceFieldUnityContainer(configuration);

            //Act
            var resolvedAdvice = container.Resolve<TestAdvice>();

            //Assert
            Assert.IsNotNull(resolvedAdvice);
        }
Example #5
0
        public void AllAdvicesShouldBeAutomaticlyRegistered()
        {
            //Arrange
            var configuration = new Configuration();

            configuration.Add <TestAdvice>(ApplyAdvice.OnEveryMethod);
            var container = new ForceFieldUnityContainer(configuration);

            //Act
            var resolvedAdvice = container.Resolve <TestAdvice>();

            //Assert
            Assert.IsNotNull(resolvedAdvice);
        }
Example #6
0
        private static void TestUnityIntegration()
        {
            var forceFieldConfiguration = new Configuration();
            forceFieldConfiguration.Add<CachingAdvice>(ApplyAdvice.OnEveryMethod);
            forceFieldConfiguration.Add<ExceptionHandlingAdvice>(new ApplyAdviceOnAllRepositories());
            forceFieldConfiguration.Add<LoggerAdvice>(new ApplyAdviceOnAllRepositories());
            forceFieldConfiguration.Add<EmptyAdvice>(ApplyAdvice.OnEveryMethod);

            var unity = new ForceFieldUnityContainer(forceFieldConfiguration);
            unity.RegisterType<ICacheProvider, RamCacheProvider>();
            unity.RegisterType<ILoggingService, LoggingService>();
            unity.RegisterType<IOtherService, OtherService>();
            unity.RegisterType<ICacheConfigurationService, ExampleOfCacheConfigurationService>();
            unity.RegisterType<IPersonRepository, PersonRepository>();

            var repository = unity.Resolve<IPersonRepository>();
            repository.Save(new Person { Key = 1, Age = 25, Name = "John" });
            repository.GetByName("John");
            repository.GetByName("John");

            var service = unity.Resolve<IOtherService>();
            var meaningOfLife = service.Bar();
        }