我想註冊一些通用接口並解決它們。註冊和解析通用接口Unity
我有註冊函數
private static void RegisterFolderAssemblies(Type t,string folder)
{
var scanner = new FolderGenericInterfaceScanner();
var scanned = scanner.Scan(t,folder); // gets the implementations from a specific folder
scanned.ForEach(concrete =>
{
if (concrete.BaseType != null || concrete.IsGenericType)
{
myContainer.RegisterType(t, Type.GetType(concrete.AssemblyQualifiedName), concrete.AssemblyQualifiedName);
}
});
}
這是由引導程序與
RegisterFolderAssemblies(typeof(IConfigurationVerification<>),Environment.CurrentDirectory);
註冊名爲似乎要經過好,但是當我嘗試解決這些問題
Type generic = typeof(IConfigurationVerification<>);
Type specific = generic.MakeGenericType(input.Arguments[0].GetType());
var verifications = BootStrap.ResolveAll(specific);
input.Arguments [0]是通用在中實現的類型的對象我也嘗試使用typeof(IConfigurationVerification <>)來代替,並得到相同的錯誤。
當ResolveAll是
public static List<object> ResolveAll(Type t)
{
return myContainer.ResolveAll(t).ToList();
}
我得到一個ResolutionFailedException與他們的消息「當前類型,Infrastructure.Interfaces.IConfigurationVerification`1 [Infrastructure.Configuration.IMLogPlayerConfiguration + LoadDefinitions],是一個接口,並且不能構造你缺少一個類型映射嗎?「
任何幫助將是偉大的。
在此先感謝
你是對的,我不知道我是如何錯過它的註冊接口以及實現。 (我怪一小時) – Amorphis
我知道這次演習,但是......你的投票讚賞:-) – lboshuizen