2
我是Autofac的新手,並嘗試使用它爲我的第一個項目工作。我不確定如何從Autofac注入註冊的助手?任何幫助,將不勝感激。使用Autofac注入註冊類
App.xaml.cs
private void Application_Startup(object sender, StartupEventArgs e)
{
var builder = new ContainerBuilder();
builder.Register(c => MyFactory.CreateHelper()).As<IHelper>();
RootVisual = new MainWindow(...);
}
MainWindow.xaml.cs
public class MainWindow
{
public IHelper IHelper {get;set;}
public MainWindow(IHelper helper)
{
iHelper = helper;
}
}
良好的格式是你的朋友。 –