Is it possible to disable the automatic instance creation behavior of UnityContainer?

UnityContainer.Resolve () will create instances that were not explicitly registered with reflection, allowing this thing:

using System;
using Microsoft.Practices.Unity;

namespace ConsoleApplication2
{
    public class Foo
    {
        public void SayHello()
        {
            Console.WriteLine("Hello");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var container = new UnityContainer();
            var foo = container.Resolve<Foo>();
            foo.SayHello();
        }
    }
}

My question is whether this behavior can be disabled if I want the class to not be automatically resolved (either with an exception raised, or with a null return)

+3
source share
3 answers

, , . - , , , , -, , "" , .

, . , , .

0

Resolve<>(), , . , , , . , Unity NULL.

0

. - :

interface IFoo{...}
class Foo:IFoo{...}
// ...
var foo = container.Resolve<IFoo>(); // Exception here
0
source

All Articles