Mindscape
  • Register
  • Login
  • YOUR CART IS EMPTY
home
Software
  • Developers Toolbox
  • LightSpeed
  • Raygun
  • WPF Elements
  • Web Workbench
  • Metro Elements
  • Silverlight Elements
  • NHibernate Designer
  • Phone Elements
  • WPF Diagrams
  • Simple DB management
  • Visual Tools for SharePoint
Downloads
Store
  • Buy online
  • Purchase order
  • Volume discounts
  • Reseller
  • Software license
  • Contact sales
Blog
Support
About
  • About Us
  • Contact
  • Testimonials
rss
twitter
facebook
Implementing Storage Policies with LightSpeed Entity Tracking Soft Deletion Timestamps for Entity Tracking and Soft Deletion User Ids for Entity Tracking and Soft Deletion Concurrent Editing Implementing Policies in HandCoded Entities Change Tracking

User Ids for Entity Tracking and Soft Deletion

Different applications identify users in different ways.  There is no default way of identifying a user.  So in order to store user names in the CreatedBy, UpdatedBy and DeletedBy fields, you must specify to LightSpeed how it should identify users.

To do this, set LightSpeedContext.AuditInfoMode in code, or set the auditInfo attribute in configuration.  The available values are defined by the AuditInfoMode enumeration.

Setting how users are identified in configuration

<add name="Test"
     auditInfo="HttpContext" />

Built-In User Identification Strategies

There are two built-in user identification strategies, HttpContext and WindowsIdentity.

·         HttpContext: The user id is taken from the HttpContext.Current.User.Identity.  The application should ensure that users are authenticated.

·         WindowsIdentity: The user id is the Windows login of the active user.

Using a Custom Identification Strategy

Some applications have their own means of identifying users, such as a custom user database or directory.  To make LightSpeed use such a custom identification method, specify the Custom AuditInfoMode, implement IAuditInfoStrategy, and set LightSpeedContext.CustomAuditInfoStrategy to an instance of that implementation.

Implementing IAuditInfoStrategy for unit testing

public class FixedAuditInfoStrategy : IAuditInfoStrategy
{
  private string _user;
  public FixedAuditInfoStrategy(string user)
  {
    _user = user;
  }
  public AuditInfoMode Mode
  {
    // Custom strategies must always return AuditInfoMode.Custom
    get { return AuditInfoMode.Custom; }
  }
  public string GetCurrentUser()
  {
    return _user;
  }
}

Using the custom strategy

_context.AuditInfoMode = AuditInfoMode.Custom;
_context.CustomAuditInfoStrategy = new FixedAuditInfoStrategy(Tests.NominalUser);

You can also specify a custom audit information strategy in configuration using its assembly‑qualified type name.  In this case the strategy class cannot take constructor parameters.

Setting a custom audit info strategy in configuration

<add name="Test"
     auditInfo="MyApp.MyAuditInfoStrategy, MyApp" />

Data Products

  • LightSpeed ORM
  • NHibernate Designer
  • SimpleDB Tools
  • SharePoint Tools

DevOp Tools

  • Raygun

Visual Controls

  • WPF Elements
  • WPF Diagrams
  • Silverlight Elements
  • Phone Elements

Popular Products

  • Web Workbench

    Modern web development for Visual Studio!

  • Mindscape Megapack

    All Mindscape products for one awesome price!

Quick Links

  • Forums
  • Blog
  • Register
  • Login
  • Contact us
  • Twitter
  • Facebook
  • Google+
  • YouTube
  • Linkedin
  • Rss

© Mindscape 2025. Mindscape is a registered trademark of Mindscape Limited.

  • Terms
  • Privacy