Appearance
Get a Service by ServiceType
Requesting the default configured object of a service type is done through the IContainer.GetInstance()
method shown below:
cs
[Fact]
public void get_the_default_instance()
{
var container = new Container(x => { x.For<IWidget>().Use<AWidget>(); });
container.GetInstance<IWidget>()
.ShouldBeOfType<AWidget>();
// or
container.GetInstance(typeof(IWidget))
.ShouldBeOfType<AWidget>();
}
cs
[Fact]
public void get_the_default_instance()
{
var container = new Container(x => { x.For<IWidget>().Use<AWidget>(); });
container.GetInstance<IWidget>()
.ShouldBeOfType<AWidget>();
// or
container.GetInstance(typeof(IWidget))
.ShouldBeOfType<AWidget>();
}