DevLabs > DevLabs Forums > Axum Incubation Project > There is no access to an immutable domain state.
Ask a questionAsk a question
 

AnswerThere is no access to an immutable domain state.

  • Monday, July 13, 2009 12:47 AMAndrei Sedoi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Why can't I get access to an immutable domain state in the following case?


    namespace ConsoleApplication
    {
        domain Domain
        {
            private readonly int number = 5;
            
            channel Channel
            {
            }
            
            private agent Agent : channel Channel
            {
                public Agent()
                {
                    int i = number;
                }
            }
        }
    }
    

Answers

  • Monday, July 13, 2009 4:57 PMArtur Laksberg MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Andrei,

    readonly cannot be accessed for several reasons. First, being a carry-over from C#, readonly doesn't mean deep immutability, so if we allowed it you would be able to mutate the data it refers to (as in, "my_readonly_member.n=10"). Second, readonly can "escape" domain constructor, so you could have a situation where a no-access agent can read a member that a constructor can write to, which is a data race.

    Check out async, const and sync modifiers. Here is an intro: http://blogs.msdn.com/maestroteam/archive/2009/05/02/empty-full-storage.aspx

    Thanks,
    Artur Laksberg - MSFT

All Replies