Example #1
0
        public void CanDefineCustomDefaultProvider()
        {
            const string Bubba = "Bubba";

            // Change the fallback / default provider to be something that yields our magic string
            var provider = new InstanceProvider(null);
            provider.Register(typeof(string), Bubba);
            CommonProvider.RegisterDefaultProvider(provider);

            // Grab the instance and check to see if its our string
            var instance = CommonProvider.Provide<string>();
            instance.ShouldBeSameAs(Bubba);
        }
Example #2
0
        public void EnsureDependencyContainerUsesItselfToGetDefaultProvider()
        {
            // Create our default provider with instructions to yield itself as an IObjectProvider
            var instanceProvider = new InstanceProvider(null);
            instanceProvider.Register(typeof(IObjectProvider), instanceProvider);

            // Register the new provider as a source for IObjectProvider
            CommonProvider.Register(typeof(IObjectProvider), instanceProvider);

            // Cause DefaultProvider to be lazy loaded and store the result
            var defaultProvider = CommonProvider.Container.FallbackProvider;

            // Check that they're the same object
            instanceProvider.ShouldBeSameAs(defaultProvider);
        }