コード例 #1
0
        public void ShouldUseFactory()
        {
            var partLocator = new PartLocator<NonSharedObject>(true);
            var instance = partLocator.GetPart();

            Assert.IsNotNull(instance);
        }
コード例 #2
0
        public void ShouldUseFactory()
        {
            var partLocator = new PartLocator <NonSharedObject>(true);
            var instance    = partLocator.GetPart();

            Assert.IsNotNull(instance);
        }
コード例 #3
0
        public void ShouldDiscoverInjectedAuthenticationService()
        {
            var injectedService = new AuthenticationService();

            CompositionContext ctx = CompositionContext.Default
                .WithGenerator(typeof(IAuthenticationService), () => injectedService)
                .WithName("ShouldDiscoverInjectedAuthenticationService");

            IAuthenticationService auth1 =
                new PartLocator<IAuthenticationService>(false, () => ctx).GetPart();
            IAuthenticationService auth2 = new PartLocator<IAuthenticationService>().GetPart();

            Assert.IsNotNull(auth1, "AuthenticationServer should not be null");
            Assert.IsNull(auth2, "AuthenticationService should be null");
            Assert.IsTrue(ReferenceEquals(auth1, injectedService), "Should have found service in CompositionContext");
        }
コード例 #4
0
        public void ShouldDiscoverInjectedAuthenticationService()
        {
            var injectedService = new AuthenticationService();

            CompositionContext ctx = CompositionContext.Default
                                     .WithGenerator(typeof(IAuthenticationService), () => injectedService)
                                     .WithName("ShouldDiscoverInjectedAuthenticationService");

            IAuthenticationService auth1 =
                new PartLocator <IAuthenticationService>(false, () => ctx).GetPart();
            IAuthenticationService auth2 = new PartLocator <IAuthenticationService>().GetPart();

            Assert.IsNotNull(auth1, "AuthenticationServer should not be null");
            Assert.IsNull(auth2, "AuthenticationService should be null");
            Assert.IsTrue(ReferenceEquals(auth1, injectedService), "Should have found service in CompositionContext");
        }
コード例 #5
0
        public void ShouldDiscoverDefault()
        {
            CompositionContext context = CompositionContext.Default
                .WithGenerator(typeof(IEntityManagerSyncInterceptor), () => new SyncInterceptor())
                .WithName("ShouldDiscoverDefault");

            var partLocator1 = new PartLocator<IEntityManagerSyncInterceptor>(false, () => context);
            PartLocator<IEntityManagerSyncInterceptor> partLocator2 = new PartLocator<IEntityManagerSyncInterceptor>()
                .WithDefaultGenerator(() => new DefaultEntityManagerSyncInterceptor());

            IEntityManagerSyncInterceptor obj1 = partLocator1.GetPart();
            Assert.IsTrue(obj1.GetType() == typeof(SyncInterceptor),
                          "Should have found the SyncInterceptor");

            IEntityManagerSyncInterceptor obj2 = partLocator2.GetPart();
            Assert.IsTrue(obj2.GetType() == typeof(DefaultEntityManagerSyncInterceptor),
                          "Should have found the DefaultSyncInterceptor");
        }
コード例 #6
0
        public void ShouldDiscoverDefaultSyncInterceptor()
        {
            CompositionContext context = CompositionContext.Default
                                         .WithGenerator(typeof(IEntityManagerSyncInterceptor), () => new SyncInterceptor())
                                         .WithName("ShouldDiscoverDefault");

            var partLocator1 = new PartLocator <IEntityManagerSyncInterceptor>(false, () => context);
            PartLocator <IEntityManagerSyncInterceptor> partLocator2 = new PartLocator <IEntityManagerSyncInterceptor>()
                                                                       .WithDefaultGenerator(() => new DefaultEntityManagerSyncInterceptor());

            IEntityManagerSyncInterceptor obj1 = partLocator1.GetPart();

            Assert.IsTrue(obj1.GetType() == typeof(SyncInterceptor),
                          "Should have found the SyncInterceptor");

            IEntityManagerSyncInterceptor obj2 = partLocator2.GetPart();

            Assert.IsTrue(obj2.GetType() == typeof(DefaultEntityManagerSyncInterceptor),
                          "Should have found the DefaultSyncInterceptor");
        }