-
Notifications
You must be signed in to change notification settings - Fork 17
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
Exclude certain derived types from registering #121
Comments
When you say, "exclude registering base classes from Library." do you mean exclude all registrations that use base classes or exclude all registrations from that derive from LibraryClass? The first case is easy, as this is controlled with behaviors. Rather than using Default, simply specify a comma separated list of which behaviors you would like turned on. In this case the behavior you want to turn off is For the second case, I think the issue is your Type map. In version 3.1.0 there was a breaking change that was introduced. Rather than the Name properties defaulting to being regular expressions they use a simplistic wildcard matching strategy. So as you have it written it would no map classes that are within the Library namespace (likely not what you were going for). Perhaps something like this? <AutoDI>
<Type Name=".Library*" Lifetime="None"/>
</AutoDI> Assuming you don't have a namespace that starts with "Library", this would remove all types that started with the name "Library". But in your example above this does nothing to the maps for that the behaviors will all for Finally it is worth knowing that when AutoDI runs, the behaviors run, and generate a bunch of mappings. Then the explicit Map/Type values are evaluated, letting them override the mappings that the behaviors added. Let me know if this is sufficient for your needs or if there is something better that could be done. |
The problem I'm having is when I request <AutoDI>
<Type Name=".Library*" Lifetime="None"/>
</AutoDI> This didn't work for me since |
Ah I think I understand the issue now (and no, my previous suggestion wont work). And unfortunately it is current "working as designed" (though the design may be flawed). The original intent with the base class stuff was to be able to request an [abstract] base class and have it automatically return the most derived class. It is also worth noting that when behaviors add potential maps, if multiple maps conflict, all of the conflicting maps are removed from the final mapping result. So in your example (with the current release) the only remaining map are: The second one is actually a bug. It should have been considered a duplicate map because it could have been considered mapped to itself, mapped to MyBaseClass, or mapped to MyClass, but because of the way that it currently throws out duplicates, On the second potential map it detects the duplicates, and removes both. So when the third potential map comes it, it is allowed. (Buggy code here). I have created branch Regardless, there is still the outstanding question of the best way to handle this. There are a couple potential ideas I have here:
Any feedback or other thoughts? |
I can only suggest the xml format. I would like to have something similar to how dotnet sdk handles project files: <ItemGroup>
<None Remove="Item/To/Remove.cs" />
</ItemGroup> In this case it could look something like: <behaviors>
<behavior Name="FullClassName" Remove="BaseClass;AnotherBassClass" Behavior="IncludeClasses" />
</behaviors> well maybe EDIT: |
Agreed. For the 3.3.0 release I only plan on addressing the bug with odd number of conflicting maps actually getting registered. This is clearly a bug, and fixing it will lay the foundation for doing custom behaviors which I think is the best solution. With that said, I am still considering adding some minor level of customization to the built-in behaviors because simply excluding some types feels like a use-case that should be supported. You are correct doing it in the |
@SlowLogicBoy the next 3.3.0 preview nuget will have this bug addressed. For an example take a look at these unit tests as well as this one. Since the bug with the registration is now address, I am going to bump the remainder of this issue to vNext (likely 3.4.0). |
right now it registers
MyClass
asMyClass
,MyBaseClass
andLibraryClass
, I would like to exclude registering base classes from Library.I tried doing:
But it doesn't work and I presume it is not intended way to do this.
Maybe there is a way to do this using
<Map>
?The text was updated successfully, but these errors were encountered: