4

I have a simple class:

public class MyWidget
{
    private string _something;

    public MyWidget(string name)
    {

    }

    public string Something
    {
        get { return _something; }
        set { _something = value; }
    }
}

that I register with Autofac:

var builder = new ContainerBuilder();
builder.RegisterType<MyWidget>();
var container = builder.Build();

If I resolve a factory and create an instance of MyWidget:

var myWidgetFactory = Container.Resolve<Func<string, MyWidget>>();
var myWidget = myWidgetFactory("test");

The property 'Something' is assigned the value "test", even though it has nothing to do with the constructor parameter. Why does Autofac think it should set the first property it comes to? How do I prevent this? I'm using Autofac v4.0.0.

Dan
  • 1,215
  • 1
  • 10
  • 22

0 Answers0