Why no RegisterType<T>() ?

Sep 8, 2008 at 2:52 PM
Edited Sep 8, 2008 at 2:56 PM

When registering types with the container, I'm wondering why I can do this: .RegisterType<Apple, Apple>(); or this: .RegisterType<Apple>(null); which both works perfectly, but I can't do this: .RegisterType<Apple>();

Why is the lifetimemanager a required parameter when adding a single type?

Thanks for a nice framework,

Sep 8, 2008 at 6:51 PM
Because with Unity you don't need to register concrete types unless you're going to configure them in some special way. So RegisterType<Apple>() is a noop - you can just .Resolve<Apple>() without having done the registration.

Those other overloads are there to provide type mapping, or let you specify a named registration or a lifetime manager. They can degenerate into a "register a single type" but that's not the intended use.


Sep 8, 2008 at 9:40 PM
Thanks for a good and fast answer.