public static void AutoWire(this object instance)
{
instance.GetType()
.GetFields(BindingFlags.Instance |
BindingFlags.NonPublic |
BindingFlags.DeclaredOnly)
.Where(i => i.IsPrivate&&i.IsInitOnly && i.Name.StartsWith("_") && i.FieldType != typeof(string)).ToList()
.ForEach(f => f.SetValue(instance, _provider.GetRequiredService(f.FieldType)));
}
在其它页面加载时就能注册类了
界面加载时调用
this.AutoWire();