ipjohnson / Grace

Grace is a feature rich dependency injection container library
MIT License
336 stars 33 forks source link

Export attributes should only be allowed on class #261

Closed jods4 closed 4 years ago

jods4 commented 4 years ago

I wanted to export some instances with attributes, so I was pleasantly surprised that ExportAttribute can be put on a property.

Some research later, I find nothing in Grace code that looks at export attributes on anything else than a class, so their attribute target should probably be changed.

ipjohnson commented 4 years ago

Were you looking to do an export of a property? In older version of Grace I supported it but dropped it a while back because it didn't seem like a useful feature. Then again attributes went out of vogue for a while when Fluent was all the rage.

jods4 commented 4 years ago

Personally I like attributes. I don't like having a central point where tens if not hundreds of exports are declared. Attributes keep the information local to where the code is and avoid merge conflicts.

I was looking to export specific instances (singletons) but it's not a key case and wouldn't say it's a very useful feature.

I was thrown-off by the contradiction that the attributes describe themselves as meaningful on properties and methods, but actually don't work. If they could target classes only I wouldn't have lost some time trying to make them work.

ipjohnson commented 4 years ago

Yeah it is interesting how fluent registrations became so popular because registering hundreds (we have 500+) by hand sounds horrible. I usually just export a whole assembly by interface and apply lifestyles based on naming convention and patch any missing piece with fluent registration (there isn't usually much).

I'll make the change to the attribute usage to clear up any confusion. Sorry for the inconvenience.

ipjohnson commented 4 years ago

I'm going to close this as completed

jods4 commented 3 years ago

@ipjohnson sorry to necro that old issue, but I do have a related question:

I have cases where some of my assemblies has to export from a factory method. Is there a way to achieve this with attributes and automatic discovery?