locked
Where's the model? RRS feed

  • Question

  • Let me start with a scenario. Let's say I have an application that maintains a ledger of transactions, like a home finance app or something. If I was doing this application in "traditional" WPF, I would create a singleton class factory called ModelRoot which would then expose a property called Ledger. I would then be able to refer to this either through code:

     

    ModelRoot.Current.Ledger.Add( new LedgerItem(....) );

     

    or through XAML through an ObjectDataProvider.

     

    What I'm curious about is in the new Acropolis way of doing things, should the LedgerPart part keep its own private copy of the model and spit out notifications as necessary, or do you think the singleton global model is a good one to maintain for an Acropolis application?

    Wednesday, June 20, 2007 3:31 PM

Answers

  • I would say AcropolisService is more appropriate than a part, simply because it is easy for other parts to access it. If you think you need a part with a view just to display the current state of your model (like a shopping cart with items in the corner of the screen) than I would create a separate part with a view just for this purpose but still would keep the service.

    Unfortunately you cannot currently implement your service as a true Singleton with private constructor, because Acropolis runtime needs the public constructor to initialize it. However if you declare the service in your Application:

     

    <AcropolisApplication.Services>

    <Model:LedgerService/>

    </AcropolisApplication.Services>

     

     

    The parts can use the same service instance through ServiceDependency:

     

    <PartFx:Part.ServiceDependencies>

    <ServiceDependency Name="ledgerService" ServiceType="{x:Type Model.LedgerService}" IsRequired="True"/>

    </PartFx:Part.ServiceDependencies>

    Thursday, June 21, 2007 3:47 PM

All replies

  • I would say AcropolisService is more appropriate than a part, simply because it is easy for other parts to access it. If you think you need a part with a view just to display the current state of your model (like a shopping cart with items in the corner of the screen) than I would create a separate part with a view just for this purpose but still would keep the service.

    Unfortunately you cannot currently implement your service as a true Singleton with private constructor, because Acropolis runtime needs the public constructor to initialize it. However if you declare the service in your Application:

     

    <AcropolisApplication.Services>

    <Model:LedgerService/>

    </AcropolisApplication.Services>

     

     

    The parts can use the same service instance through ServiceDependency:

     

    <PartFx:Part.ServiceDependencies>

    <ServiceDependency Name="ledgerService" ServiceType="{x:Type Model.LedgerService}" IsRequired="True"/>

    </PartFx:Part.ServiceDependencies>

    Thursday, June 21, 2007 3:47 PM
  • Well, that's great but it doesn't tell me where to put the model. Services by definition are functional and not models. They contain methods, not state. If you want me to create a stateful service then we will have to argue about architecture because I won't do it.

     

    My original question was: do I create a single global model, or do I have a part that has its own model that can be updated by external services and parts by exposing the model as a connection point.

    Thursday, June 21, 2007 3:55 PM
  • In this case I would create a single global model.

    I would also wrap it in an AcropolisService but since you're not interested in having a stateful service and this scenario is clearly stateful, let's not get into this.

    Thursday, June 21, 2007 4:19 PM
  • Having a service that knows how to retrieve an instance of your model does not make the service stateful.

    Friday, June 22, 2007 9:31 PM