Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7127977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:05:23+00:00 2026-05-28T11:05:23+00:00

I could be missing something obvious here… But as I learn to appreciate the

  • 0

I could be missing something obvious here…

But as I learn to appreciate the glory of IoC and ctor injection I am having trouble reconciling this with object graph serialization. Are the two patterns compatible? Why (or why not)?

Suppose there is:

public class Foo
{
    #region invariants
    private readonly List<IBar> _bars;
    private readonly Guid _id;
    #endregion

    public Foo( List<IBar> bars, Guid id )
    {
        _bars = bars.CannotBeNull("bars");
        _id = id.CannotBeNull("id");
    }

    public List<IBar> Bars { get { return _bars; } }

    //some other state I want serialized
}

public static class Ex
{
    public static T CannotBeNull<T>( this T obj, string paramName = "" )
    {
        if ( null == obj ) throw new ArgumentNullException(paramName);
        return obj;
    }
}

I like the iron clad saftey of protecting class invariants through ctor injection. It gives my objects the certainty that they will always have what they need. Is injection of invariants at odds with the repository pattern? Maybe there is a DTO layer and a factory pattern somewhere that bridges the gap… ?

Looking for sagely advice… Are the two patterns compatible? Why (or why not)?

PS: I know about IDeserializationCallback but I don’t see how it helps with ‘private readonly’ invariants

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:05:24+00:00Added an answer on May 28, 2026 at 11:05 am

    There is an article by Mark Seemann about that topic, At the Boundaries, Applications are Not Object-Oriented. Bottom line is: at the borders applications are not object oriented. If there is some kind of translation (like serialization) happening, your class invariants can’t be protected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I may be missing something obvious here, but how could I rewrite this code
I may be missing something obvious here, but how could I rewrite this code!
I feel like I'm missing something blindingly obvious here, so low hanging fruit for
Am I missing something obvious here, I cannot find a way to assign an
I'm sure I'm missing something obvious here. I have a about twenty data-bound GridViews,
I'm having trouble to do something that I though it would be a 5
I'm new to Objective-c, so sorry if I'm missing something really obvious. I'm currently
Could somebody please name a few. I could given time, but this is for
I've done something similar to this with hbm files but so far I haven't
Apologies for if the question is obvious but I can't figure out why it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.