-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Allow specifying value converter instance in ConfigureConventions #28085
Comments
@AndriySvyryd Isn't this by-design so that it is always compatible with compiled models? |
It is, but we could allow it if there are enough users who need it and don't use compiled models. |
DI resolution would be awesome. Although, @andriysavin I would recommend storing all Date properties as UTC in database and handling the display on client. |
@Cubelaster sorry for delayed response. Unfortunately, in my case the DB historically stores date/time in particular time zone, and there is no desire to migrate the data (and the code which is bound to this approach). I won't be surprised if I'm not alone with such problem. |
Would appreciate being able to pass an instance or resolve constructor parameters from DI as well! I currently have an extension method which simply loops through all columns in all tables in OnModelCreating and assigns them a value converter instance, but I just learned about |
@QuantumToasted Implementing this would not help your case, since it would require a new model to be built every time a different converter is used. #12205 would be more appropriate for this. |
In
ConfigureConventions
I can specify a converter for all properties of certain type. But unlike with "regular" converter configuring, here I can only specify converter type, but not instance:This limits only to converters which have parameterless constructors. But in some cases it's useful to be able to pass some additional information to particular converter usage.
For instance, I have a converter which converts a
DateTimeOffset
toDateTime
in specified time zone. Converter's constructor has this look:public DateTimeOffsetToDateTimeConverter(TimeZoneInfo timeZone)
To configure properties with this converter with a specific time zone I have to derive new type which hardcodes this time zone, so it has parameterless contructor and specifying just type is enough. But even this trick will not work if you need to decide on parameter value at run time.
The text was updated successfully, but these errors were encountered: