我已经注册了这样的服务:
builder.RegisterType<NoticeEmail>().Keyed<INoticeChannel>(ChannelType.Email);
builder.RegisterType<NoticePushover>().Keyed<INoticeChannel>(ChannelType.Pushover);
我正按以下方式解决这些问题:
public INoticeChannel Resolve(ChannelType type, string message)
{
var r = _context.ResolveKeyed<INoticeChannel>(type);
Type myType = Type.GetType(r.GetType().Name);
var t = JsonConvert.DeserializeObject(message, myType);
return r;
}
解析工作得很好但我也想用message
的json数据启动对象并返回特定对象。我怎样才能做到这一点?
答案 0 :(得分:0)
这是正确的代码:
var r = _context.ResolveKeyed<INoticeChannel>(type);
Type myType = Type.GetType(channel.GetType().AssemblyQualifiedName);
var t = JsonConvert.DeserializeObject(message, myType);