Add ability to inject into module initializer #165
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for library initialization. It looks for the ModuleDefinition's type and then creates a static constructor if one isn't already found.
The .cctor is called when the module is loaded (not necessarily on assembly load).
This is mostly done. I need to write some unit tests for it but it doesn't seem AssemblyGenerator supports weaving in settings so by default AutoInit is true which means AutoLibraryInit is off. Maybe something to look into? Turning it on does mangle a lot of the unit tests because DI.Init tries to get called twice. Hey, at least I know it's working 👍
I'd also like to discuss the setting name. I tried to come up with something good but it might not be the best while also debating whether to turn the AutoInit from a bool into an enum. Maybe like
That would be a breaking change so I decided not to for now.
I've never used AutoDI but it does look neat! Once (and if) this PR is accepted, I'd be happy to update the relevant wiki related to configuration as well!
Related: #154