Skip to content

How do I add a custom formatter in ASP.NET and AutoFac #421

Answered by MorganBard
MorganBard asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, after a bit of research, I got this and it seems to work:

In my ApplicationModule class (where I do all my dependency injection registrations) i have this in the Load method:

builder.Register(c =>
{
   SmartFormatter formatter = new SmartFormatter()
      .AddExtensions(
         new StringSource(),
         // will automatically be added to the IFormatter list, too
         new ListFormatter(),
         new DictionarySource(),
         new ValueTupleSource(),
         new ReflectionSource(),
         // for string.Format behavior
         new DefaultSource(),
         new KeyValuePairSource())
      .AddExtensions(
         new PluralLocalizationFormatter(),
         new ConditionalF…

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
6 replies
@MorganBard
Comment options

@axunonb
Comment options

@MorganBard
Comment options

@axunonb
Comment options

@MorganBard
Comment options

Comment options

You must be logged in to vote
3 replies
@axunonb
Comment options

@MorganBard
Comment options

@axunonb
Comment options

Answer selected by axunonb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants