예제 #1
0
        public static void RegisterReplacementFacetFactory <TReplacement, TOriginal>(IUnityContainer container)
            where TReplacement : IFacetFactory
            where TOriginal : IFacetFactory
        {
            int order = FacetFactories.StandardIndexOf(typeof(TOriginal));

            container.RegisterType <IFacetFactory, TReplacement>(
                typeof(TOriginal).Name,
                new ContainerControlledLifetimeManager(),
                new InjectionConstructor(order));
        }
예제 #2
0
        //Helper method to, subsistute a new implementation of a specific facet factory, but where the constructor
        // of the new one takes: a numeric order, and the standard NOF implementation of that facet factory.
        public static void RegisterReplacementFacetFactoryDelegatingToOriginal <TReplacement, TOriginal>(IUnityContainer container)
            where TReplacement : IFacetFactory
            where TOriginal : IFacetFactory
        {
            int order = FacetFactories.StandardIndexOf(typeof(TOriginal));

            //Register the orginal (standard NOF implementation). Note that although already registered by StandardUnityConfig.RegisterStandardFacetFactories
            //that will be as a named impl of IFacetFactory.  This will be the only one registered as the concrete type
            //PropertyMethodsFacetFactory so doesn't need to be named.
            container.RegisterType <TOriginal>(
                new ContainerControlledLifetimeManager(),
                new InjectionConstructor(0)); //We don't care about the order, because this isn't called as a FacetFactory AS SUCH.
            //but we still need one for the constructor

            // Now add replacement using the standard pattern but using the same Name and orderNumber as the one being superseded.
            // The original one will be auto-injected into it because of the implementation registered above
            container.RegisterType <IFacetFactory, TReplacement>(
                typeof(TOriginal).Name, //Following standard pattern for all NOF factories
                new ContainerControlledLifetimeManager(),
                new InjectionConstructor(order, typeof(TOriginal)));
        }
예제 #3
0
        private static int GetExistingOrder <TOriginal>()
        {
            var order = FacetFactories.StandardIndexOf(typeof(TOriginal));

            return(order == -1 ? ParallelReflect.FacetFactories.StandardIndexOf(typeof(TOriginal)) : order);
        }