Reputation: 811
I have two projects, one of them Web API and other is a shared project. To register my services I use:
var serviceType = typeof(IService);
var allTypes = Assembly.GetExecutingAssembly()
.GetTypes()
.Where(x => serviceType.IsAssignableFrom(x))
.ToList();
However, services from shared project aren't getting registered.
How to get types from shared project?
Upvotes: 0
Views: 371
Reputation: 811
Not sure is my solution elegant enough or not, but I put a Helper class into shared project with
var serviceType = typeof(IService);
var allTypes = Assembly.GetExecutingAssembly()
.GetTypes()
.Where(x => serviceType.IsAssignableFrom(x))
.ToList();
and it gave me what I wanted.
Upvotes: 0
Reputation: 43
The types defined in your shared project can be found in the compiled assembly for your WebApi project.
When building a project that references a shared project, the sources from the shared project are compiled as if they were part of the projet referencing it, not in a separate assembly.
So if you have a class ServiceImpl implementing IService in your shared project, the compiled WebApi assembly will expose it.
If you cannot find the type in the compiled assembly then the problem is elsewhere. Maybe the reference is missing? Maybe the build is failing and the code that is executed isn't up to date?
Upvotes: 3