73 Replies
@maxmahem post here
Taking it out of #chat
something like that.
unless I'm misunderstanding you. Do you need to get multiple different options in the same class?
No, one instance of options per attribute
But I would likely use one attribute per class
Hold on, I’ll have to switch computers to make a non working demo
yeah, then something like the above should work. MS's thing uses a different syntax, but the principle is the same.
The problem for me is I have a somewhat convoluted method for deserializing data back into these instances, which is tricky to do, and currently relies on inheritance, so this strategy would mess it up.
i dont see how it does
it's tangental to this, but I've got a whole scheme for loading data back in to like object instances from serialization... not hard to deserialize them of course, but STJ just produces a new object and I can't easily just have that object replace the current object in my IoC container, so I've got to copy the data over.
And doing that currently relies on them all being sub-classes of a given type.
I could probably switch over to them implementing an interface but, regardless of what I do, I can't have a JsonSerializationOption implement that interface, so there probably isn't any easy way to collect them with all my other options.
anyways that's more a me problem, you aren't likely to want to do any of this 😛
this is what i mean:
if a class/method doesnt have that attribute, global serializer options are used. If it does have it, then the options from that attribute instance is used
how would you use DI there?
ah, I see I see.
well.. if you can't use constructor injection autofac at least can do property injection, though I don't know if you can use it along with keyed services.
well you can use DI in general but only if the attribute lets you
I think we may be talking cross purposes though. Is there some reason you can't use ctor injection? It feels like a better way to go instead of trying to resolve what you want manually via reflection.
so im still wondering how DI helps here
what service do you use
i can resolve any service i have registered in my controller no problem
but I mean you could do...
and do what with those services?
pass them to whatever needs the options?
i cant pass a service up to an attribute tho
I'm confused, is this not where they are needed?
does
LegcyController
not perform serialization?No, the framework does it after Ok() or the return in the method happens
The controller itself does not do it
ahhh I see.
It CAN, but the framework does it
gotcha. Hmm, well I don't know how you can instruct the frameworks automagic to behave differently.
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
yeah I was just going to suggest
you can write your own custom converter it could probably be just a passthrough
and add the necessary options to the
Read
and Write
methods
kind of messy though, but it would work.Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Is addjsonoption a method?
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
ngl I'm fairly lost t this point, lol.
Lol
Wat? No
I want to serialize the response
Not the controller itself
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
my b. I see it doesn't make sense now. I think I finally get it.
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
I guess for both
Yeah
But I want to do it on a per controller or controller method basis
Or maybe just controller
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Which is easily doable with the attribute usage
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Right, but I want the framework to do that
Via an attribute
I know that way is possible
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
I want to use controller attribute decoration to drive it
Is that possible?
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Because it’s easier than running serialization manually
Code gold
Golf
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Because that changes it on the type itself
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
What do you mean a dot with JsonPropertyName?
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
And that sets it no matter how many endpoints I have that returns or deserializes that?
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
That isn’t what I want
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
That’s not what I want
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
I get that
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Ok, so is it doable with .Net?
The attribute method I demoed above
If not, then that’s fine
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
I see
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Makes sense
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Ok
How can I not do it that way and do it the way I want to try?
If it’s possible
That’s clearly the best way
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
I want to know another way
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
I meant the way you gave examples of
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
They way you showed is the best way to handle different prop names with api versioning
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
I see
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
So I’ll keep on searching then
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Yes because I want to do something specific
That isn’t being solved by your suggestions
I would recommend looking at my code at the very beginning of this thread