I would like to generate a text output list that traverses my constructor dependencies for a class or list of classes. I assume I would use reflection in some way to do this? And have protection against circular dependencies.
https://stackoverflow.com/a/29704045/254257 This seems to be what I would want, but they provided no code. That question is on a similar track, but they just assume you have start with a dictionary with your dependencies already outlined as strings. So I guess how would I get that to start with.
Say I have the following:
public class UserService(IGroupService groupService, ILoggingService loggingService)
public class GroupService(IUserService userService, IRoleService roleService, ILoggingService loggingService)
public class RoleService(ILoggingService loggingService)
I would want some code to output something like this:
UserService
----GroupService
--------UserService CIRCULAR DEPENDENCY (stops going any deeper)
--------RoleService
------------LoggingService
--------LoggingService
----LoggingService
If I wanted to check dependencies on only the UserService, with the actual concrete implementation of the interfaces.
I know I can var type = typeof(UserService)
as a starting point, but I've only ever worked with properties before so not sure what to do next.
I would imagine I would somehow need to get the constructor parameters, the types of those, then get the actual implementations and repeat, somehow also making sure I don't get stuck in a loop if I have any circular dependencies. Not sure how to do any of that so help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire