Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Now that you've read part I perhaps you can answer this.
What does this code do?
class FO : IEnumerable
{
public IEnumerator GetEnumerator()
{
throw new NotImplementedException();
}
}
class Program
{
static void Main(string[] args)
{
var cb = new ContainerBuilder();
cb.Register(ctx => new FO()).As<IEnumerable>().InstancePerLifetimeScope();
cb.Register<Func<FO>>(ctx => { return () => new FO(); }).As<Func<IEnumerable>>();
var x = cb.Build();
using (var s = x.BeginLifetimeScope())
{
var f = s.Resolve<Func<IEnumerable>>();
var i1 = f();
var i2 = f();
var ie = x.Resolve<IEnumerable>();
}
}
}
In particular
Are i1, i2, and ie distinct?
What if you comment out the line cb.Register<Func<FO>>(ctx => { return () => new FO(); }).As<Func<IEnumerable>>();?