micah
micah

Reputation: 8096

Unity Resolve Without Params?

I am using Unity Container. I register my dependency like this-

container.RegisterType<IMyService, MyService>();

And I expect to resolve that type like this-

container.Resolve<IMyService>();

But there is no parameterless Resolve. The only option I have is one where I have to give the type, the "name" (a string), and an array of ResolverOverride.

Why can't I just resolve the interface I registered?

Upvotes: 0

Views: 100

Answers (2)

Tipx
Tipx

Reputation: 7505

Your registration and your resolution should be fine. I'd say the problem is either you're not doing using Microsoft.Practices.Unity; (the generic resolution are extension methods) or that the container you register in and the one you resolve from aren't the same.

If you don't want to do using using Microsoft.Practices.Unity;, then you'll have to do something like this not to use the generic method :

IMyService myService = (IMyService)container.Resolve(typeof(IMyService));

If you add a breakpoint at the resolve, inspect the container and you see that there are no registrations, it probably means you're not using the same instance of the container.

Upvotes: 1

Seven Delta
Seven Delta

Reputation: 1

There are different types of resolving depending on usage. You can resolve by Type, resolve by registration name and type, resolve all objects of type and resolve by using override. It depends on the dependency type that you are trying in your example above.

Upvotes: 0

Related Questions