protected override void Initialize()
        {
            TypeRegistrationTrackerExtension.RegisterIfMissing(Container);

            m_CompositionContainer = PrepareCompositionContainer();

            Debug.Assert(Container == Context.Container);

            Debug.Assert(Container.IsTypeRegistered(typeof(CompositionContainer))
                         == Container.IsRegistered <CompositionContainer>());

            Debug.Assert(Container.IsTypeRegistered(typeof(CompositionContainer))
                         == UnityContainerHelper.IsTypeRegistered(Container, typeof(CompositionContainer)));

//#if true || NET40
//            if (!Container.IsTypeRegistered(typeof(CompositionContainer)))
//            {
//                Context.Container.RegisterInstance(typeof(CompositionContainer), m_CompositionContainer);
//            }

//            //IServiceLocator locator = ServiceLocator.Current;
//#else
//            Context.Locator.Add(typeof(CompositionContainer), m_CompositionContainer);
//#endif

            Context.Policies.SetDefault <ICompositionContainerPolicy>(new CompositionContainerPolicy(m_CompositionContainer));
            Context.Strategies.AddNew <CompositionStrategy>(UnityBuildStage.TypeMapping);
            Context.Strategies.AddNew <ComposeStrategy>(UnityBuildStage.Initialization);
        }
        protected override void Initialize()
        {
            TypeRegistrationTrackerExtension.RegisterIfMissing(Container);

            m_CompositionContainer = PrepareCompositionContainer();

            Context.Policies.SetDefault <ICompositionContainerPolicy>(new CompositionContainerPolicy(m_CompositionContainer));
            Context.Strategies.AddNew <CompositionStrategy>(UnityBuildStage.TypeMapping);
            Context.Strategies.AddNew <ComposeStrategy>(UnityBuildStage.Initialization);
        }
        private static UnityContainer ConfigureUnityThenMef()
        {
            var container = new UnityContainer();

            TypeRegistrationTrackerExtension.RegisterIfMissing(container);

            var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            container.RegisterType <IUnityComponent, UnityComponent>();
            container.RegisterType <ICountableUnityComponent, CountableUnityComponent>();
            container.RegisterCatalog(catalog);

            return(container);
        }
        private void ConfigureUnityContainer()
        {
            TypeRegistrationTrackerExtension.RegisterIfMissing(m_UnityContainer);

            var tracker = m_UnityContainer.Configure <TypeRegistrationTrackerExtension>();

            foreach (var entry in tracker.Entries)
            {
                AddExportDefinition(entry.Type, entry.Name);
            }

            tracker.Registering += (s, e) =>
                                   AddExportDefinition(e.TypeFrom ?? e.TypeTo, e.Name);

            tracker.RegisteringInstance += (s, e) =>
                                           AddExportDefinition(e.RegisteredType, e.Name);
        }
        /// <summary>
        /// Method called by <see cref="ContainerExportProvider"/> in order
        /// to initialize the adapter.
        /// </summary>
        public override void Initialize()
        {
            TypeRegistrationTrackerExtension.RegisterIfMissing(container);

            var tracker = this.container.Configure <TypeRegistrationTrackerExtension>();

            foreach (var entry in tracker.Entries)
            {
                OnRegisteringComponent(entry.Type, entry.Name);
            }

            tracker.Registering += (s, e) =>
                                   OnRegisteringComponent(e.TypeFrom ?? e.TypeTo, e.Name);

            tracker.RegisteringInstance += (s, e) =>
                                           OnRegisteringComponent(e.RegisteredType, e.Name);
        }
        /// <summary>
        /// Initial the container with this extension's functionality.
        /// </summary>
        /// <remarks>
        /// When overridden in a derived class, this method will modify the given
        /// <see cref="ExtensionContext"/> by adding strategies, policies, etc.
        /// to install it's functions into the container.
        /// </remarks>
        protected override void Initialize()
        {
            TypeRegistrationTrackerExtension.RegisterIfMissing(Container);

            this.compositionContainer = PrepareCompositionContainer();

            // Main strategies
            Context.Strategies.AddNew <EnumerableResolutionStrategy>(UnityBuildStage.TypeMapping);
            Context.Strategies.AddNew <CompositionStrategy>(UnityBuildStage.TypeMapping);
            Context.Strategies.AddNew <ComposeStrategy>(UnityBuildStage.Initialization);

            // Policies
            Context.Policies.Set <IBuildPlanPolicy>(
                new LazyResolveBuildPlanPolicy(), typeof(Lazy <>));

            Context.Policies.SetDefault <ICompositionContainerPolicy>(
                new CompositionContainerPolicy(compositionContainer));
        }
        public void MefCanResolveTypesRegisteredInUnityAfterTrackingExtensionIsAddedTest()
        {
            // Setup
            var unityContainer = new UnityContainer();

            // Enable tracking
            TypeRegistrationTrackerExtension.RegisterIfMissing(unityContainer);

            // Registration
            unityContainer.RegisterType <IUnityOnlyComponent, UnityOnlyComponent2>("unityComponent2");

            // Further setup
            var adapter         = new UnityContainerAdapter(unityContainer);
            var provider        = new ContainerExportProvider(adapter);
            var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            var container       = new CompositionContainer(assemblyCatalog, provider);

            var component = container.GetExportedValue <IUnityOnlyComponent>("unityComponent2");

            Assert.That(component, Is.Not.Null);
            Assert.That(component.GetType(), Is.EqualTo(typeof(UnityOnlyComponent2)));
        }
 /// <summary>
 /// Returns whether a specified type has a type mapping registered in the container.
 /// </summary>
 /// <param name="container">The <see cref="IUnityContainer"/> to check for the type mapping.</param>
 /// <param name="type">The type to check if there is a type mapping for.</param>
 /// <returns><see langword="true"/> if there is a type mapping registered for <paramref name="type"/>.</returns>
 /// <remarks>In order to use this extension method, you first need to add the
 /// <see cref="IUnityContainer"/> extension to the <see cref="TypeRegistrationTrackerExtension"/>.
 /// </remarks>
 public static bool IsTypeRegistered(this IUnityContainer container, Type type)
 {
     return(TypeRegistrationTrackerExtension.IsTypeRegistered(container, type));
 }