Implementing a CslaIdentity subclass in the object factory

Implementing a CslaIdentity subclass in the object factory

Old forum URL: forums.lhotka.net/forums/t/9555.aspx


MichaelBBonner posted on Monday, September 20, 2010

This is for CSLA 4.01:

I have implemented a custom identity class that inherits from CslaIdentity.  I have the data access portions working in embedded DataPortal_Fetch methods inside my custom class.  The rest of my app business objects all use data access code located in Object Factory classes.  I'm a bit stuck on how to migrate my identity class DataPortal_Fetch method to an object factory method.  Specifically, I'm able to populate all of my custom identity properties throught the setproperty methods, but I can't figure out how to access the protected IIdentity properties that are implemented in the CslaIdentity base class (AuthenticationType, IsAuthenticated and the Name properties.)

Can anyone give me any hints on how I should do this?  All the samples I've found either use the DataPortal_Fetch code or if they implement an object factory they're not inheriting from CslaIdentity with it's protected properties.

Thanks...

Mike :-)

JonnyBee replied on Tuesday, September 21, 2010

Implement a simple Fetch method like this in yoy custom identity class:

      public void Fetch(string userName, IEnumerable<string> roles)
      {
        if (userName != null)
        {
          Name = userName;
          IsAuthenticated = true;
          var roleList = new MobileList<string>();

          foreach (var role in roles)
            roleList.Add(role);
          Roles = roleList;
        }
        else
        {
          Name = "";
          IsAuthenticated = false;
          Roles = new MobileList<string>();
        }
      }

and call this method with data loaded from in your factory class.

If you want to "hide" this method you could make it Internal and use the InternalsVisibleTo attribute to make it visible only to you ObjectFactory assembly.

MichaelBBonner replied on Thursday, September 23, 2010

Thanks Jonny, that was exactly what I needed!!!

Copyright (c) Marimer LLC