Tôi đang sử dụng tính thống nhất để quản lý dịch vụ của mình trên máy chủ ứng dụng nhưng vì một lý do nào đó tôi không thể sử dụng phương thức 'GetAllInstances'. Điều kỳ lạ là 'GetInstance' cho cùng loại dường như hoạt động tốt!Unity 'GetAllInstances' không trả lại bất cứ điều gì
Dưới đây là cấu hình:
<alias alias="IService" type="Atom.Server.Infrastructure.Interface.Service.IService, Atom.Server.Infrastructure.Interface"/>
<alias alias="IAtomCommandService" type="Atom.CommandServer.AtomCommandService.Interface.IAtomCommandService, Atom.CommandServer.AtomCommandService.Interface"/>
<alias alias="AtomCommandService" type="Atom.CommandServer.AtomCommandService.AtomCommandService, Atom.CommandServer.AtomCommandService"/>
<register type="IService" mapTo="AtomCommandService">
<lifetime type="Singleton"/>
</register>
<register type="IAtomCommandService" mapTo="AtomCommandService">
<lifetime type="Singleton"/>
</register>
Ý tưởng được rằng khi máy chủ khởi động, tôi cần để có thể nhận được tất cả các trường hợp cấu hình của IService để khởi chúng.
IUnityContainer container = ConfigureUnityContainer();
UnityServiceLocator locator = new UnityServiceLocator(container);
var single = locator.GetInstance<IService>();
var all = locator.GetAllInstances<IService>().ToList();
Như tôi nói, tác phẩm đơn lẻ, nhưng tất cả đều không trả về gì cả. Ngay cả khi tôi loại bỏ ánh xạ IAtomCommandService từ cấu hình và chỉ có IService nó vẫn không hoạt động. Bất kỳ ý tưởng về nơi tôi sẽ sai với điều này?
Cảm ơn Mark - Tôi đã nhận ra điều này ngay sau khi tôi đăng câu hỏi! Luôn luôn là con đường! –