-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide design time validation for LifetimeManager derivatives #90
Comments
When upgrading I hit issues with that change that forced me to cast between I think it would be better to have a hierarchy like An alternative would be to make this into runtime validation. I think this change should be made. It could also be done by adding an What do you think? |
Any runtime validation is slower than current implementation. Some lifetime managers support more than one type of registrations, to do this with enums would require doing bit masks and multiple if(...) checks, and etc. The goal is to make Unity as fast as possible and casting to interface at design time does not introduce any overhead. |
Registration normally is a one-time operation and a single cast takes very little time compared to anything else. Runtime checking seems feasible. I see your point why this enum idea would not work. I think it would be best to revert the change. It breaks the type system for too little gain. |
I could add an interface ILifetimeManager with all other interfaces deriving from it. It should create the lowest denominator to 'cover it all' cases. If you could point me to the case where type system is broken I could fix it as well. |
I had code similar to the following:
And then I used This code is broken by the type system changes. I need This is what I mean when I say the type system is broken. I solved this issue for me simply by casting. So it's not too big of a deal but I wanted to write this up to give you an idea of what I was talking about. Feel free to close this if you plan no further action. |
Description
Currently RegisterType, RegisterInstance, etc. will accept any lifetime manager with no regard if it is compatible with corresponding registration type.
Problem
It is possible to register
instance
withTransientLifetimeManager
, for example.Solution
Add following interfaces to specify compatible registration type for the lifetime managers:
Change IUnityContainer interface to support these interfaces:
The text was updated successfully, but these errors were encountered: