Fluent configuration support for CsvOutputFormatter
See original GitHub issueHello community,
I would very much like to add ‘fluent’ configuration support for CsvOutputFormatter. It would work similarly to FluentValidation or EF, and would look like:
Startup.cs
services
.AddMvc()
.AddCsvSerializerFormatters(options =>
options.RegisterConfigsFromAssemblyContaining<BusinessProfile>();
);
InvoiceFormatterConfig.cs - a config
public class InvoiceFormatterConfig : CsvFormattingConfiguration<InvoiceModel>
{
public void Configure(CsvFormattingBuilder<InvoiceModel> builder)
{
builder
.UseHeaders()
.ForHeader("Name")
.UseProperty(i => i.Name)
.ForHeader("GrandTotal")
.UseProperty(i => i.InvoiceDetails.GrandTotal);
}
}
CsvOutputFormatter would use this configuration and would be able to generate CSV based on it. Please let mne know what do you think. I am doing it anyway for my project, I just think it’s something that would be far better than creating separate model type with primitive properties and using automapper to map entity type to our new model––which would exist only for the purpose of formatters. What do you think? Are you interested in my contribution?
ps: this could be also implemented for other formatter types.
Best Regards Piotr Kolodziej
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Yes just push your changes to a new branch in your fork. You will then be able to open a PR from your fork into WebAPIContrib.Core
master
.As soon as you push a branch with changes to your fork, and navigate to the root of WebApiContrib.Core repo, GH will automatically detect that you have some changes and offer a new button to open a PR.
Alternatively you can always trigger a PR from a fork branch using the following link: https://github.com/WebApiContrib/WebAPIContrib.Core/compare/master...piotrkolodziej:NAME_OF_YOUR_BRANCH
@damienbod Let me work on a prototype for few days and reply to your question when I have more details.