Tag Archive for 'xLim' Page 2 of 5



Long story made short: Project Report for the xLim 1

xLim 2 is a set of principles/guidelines that come from some experience and serve specific purpose of efficiently building flexible and light distributed information management systems.

Long before the xLim 2 there was xLim 1 (or simply “Lim” at that time). It was purely a research/study project undertaken in spring 2007 to explore efficient ways of building distributed Smart Client applications for information management purposes. It took 52 days to get from the project initialization phase to the proper close-out.

As you may know, one of the PM principles is to capture all the “lessons learned” on the close-out before moving to another project. That’s how it was done with the Lim 1 as well.

If you are interested in the history, then you can download xLim 1 Project Report. It is a short 15 page summary that highlights major areas that constitute the body of knowledge captured in the course of xLim 1 project.

Additionally there is an archive of screenshots (referenced as Finals.zip in the report document). Here are some pictures from it to give you the idea:

Lim System Explorer   Simple web dashboard for lim server   Project extension module for xLim 1

Right now this old report seems to be quite naive and incomplete (it actually is), since there has been so much learned with xLim 2 (it looks like it would be extremely hard to keep the xLim 2 report under 50 pages). Yet, it was an important step. Without it xLim 2 could not have started and branched off several commercial implementations.

Any comments, feedback or questions are welcome.

PS: I definitely wish that other development teams (esp. DevExpress XAF team) published reports like this one (or in any other manner that attempts to capture information essential to the efficient development and delivery of frameworks/platforms and their implementations).

Running xLim under Mono 1.2.6

There’s a small update to the last post on xLim portability. The situation is a bit better than it seemed to be.

XPO + Mono (SUSE SLED)

XPO runs under Mono. It can’t work with the the Microsoft SQL Provider since the MS SQL support under Mono is far from perfect for obvious reasons. MySQL provider does work but, as developers have found out, you’d need to change

string[] strArray = (string[])new ArrayList(dictionary.Keys).
  ToArray(typeof(string));

to

string[] strArray = new string[dictionary.Keys.Count];
dictionary.Keys.CopyTo(strArray, 0);

in the XPO sources in order for the distributed caching to work. That’s because dictionaries in Mono do not have full support yet.

Autofac + Mono (SUSE SLED)

There are 6 unit test failures:

BugFixture.IncorrectExceptionThrown1
Builder.ConcreteRegistrarFixture.RegisterThreeServices
Builder.ConcreteRegistrarFixture.
  RegisterTypeAsSupportedAndUnsupportedService
Component.Registration.ContextAwareDelegateRegistrationFixture.
  CreateFromStrongFactory
ContainerFixture.IntegrationTest
DisposerFixture.ReferenceNotHeld

Additionally there is an issue while using binary remoting across the platforms (from SLED+Mono to .NET Windows and vice versa). DateTime cannot get through, for some reason.

Theoretically, Autofac, XPO and the design with the portability in mind is all you need in order to create xLim server and engine functionality that works on Mono. So we’re in good shape here for the xLim 3 server prototypes by summer.

Web UI has got some chance of being implemented quite soon in a performant manner as well (Silverlight grid, as stated in “DevExperience Roadmap 2008″, could be delivered on summer). Additionally there is some chance that existing ASP.NET controls would work under Mono as well.

The picture for the xLim Desktop UI under Mono so far is still the same - there are no DevExpress controls any time soon, unless Silverlight grid would be capable of running on desktop. But that’s just a tiny fraction of the required UI bits.

Managing xLim 2 flexibility: IoC Container Inspector

In the last post I’ve blogged about the schema manager application for the xLim 2 approach for building flexible solutions. We go on from here.

Schema Manager encapsulates three different ideas:

  • Container Inspector
  • Configuration Manager
  • Validation Test Runner

These three pieces are logically linked to each other, and because of that there’s the synergy effect. It makes the resulting combination even more efficient and easy to implement.

Let’s talk about the container inspector bit for a while.

IoC Container Inspector UI for the xLim manager

The idea of the container inspector comes from the StructureMapExplorer and the CAB visualizer. Both had helped me a lot in understanding and visualizing what exactly happens within the multi-scoped applications (and why does this happen).

In this solution the container inspector is responsible for retrieving and displaying the information about the “Loaded Modules” sub-tree. It is implemented for the autofac as a simple ContainerInterceptor class that allows us to capture all the calls to the container with IComponentRegistration data. Then, we simply take all modules to be loaded and run them against this container interceptor one by one. And then we just take note of every registration that takes place (just 100 lines of code to do that).

Note, that the interceptor has to forward the calls to the real container, since modules are actually loaded in this virtual environment. And within the load process it is a common thing for some extension module to registers item in the service provided by the core module (or augment it).

Additionally the Container Inspector allows us to run one more validation check on the composite schema, just to make sure that the components and services that are referenced there actually exist. This is useful for the cases where modules do not create their schema bits on-the-fly, but rather preload existing schema bit from the resources. Of course the SchemaManager would detect the broken links and throw exceptions, but who wants to debug the logics when you can see only one error at a time? That’s simply inefficient.

With a little bit of imagination one can make the Container Inspector more powerful than this by:

  • Providing short descriptions for the modules and services via the attributes (usable when the modules are distributed to the other developers)
  • Grouping all named implementations by the supporting interface(s) (it is not needed within xLim 2, since the composite schema handles this in a flexible way)
  • Running validation tests for the components that support this (we’ll get to that later)
  • Exploring the properties of any given module, letting you to configure them and creating *.config file for the loaded modules.
  • Linking the upper container to NMock2 (we’ll talk about the MockContainer approach a bit later) attempting to resolve any given component (that’s one of the reasons not to put any scope-specific logic into the constructor), reporting all container dependencies for the component including these that are not satisfied by the root application scope (that’s the scope the modules get loaded into).

The last item would probably be helpful for xLim quite soon since a lot of modules do that kind of trick:

  • Register scope-specific items that use some new service
  • Register that new service in the root application scope.

Now, what happens, when the scoped item get resolved within some child scope? It pulls that service right from upper scope and would fail if it is not there. That’s the logical dependency. If the service is registered within the same module with the scoped component, then it is easy to remember and manage. But if the service is registered within one module (i.e.: IExtensionWorkflow32 from Extension.Core) and then other components depend on it (i.e.: ExtensionDesktopView from Extension.Client and ExtensionWebView from Extension.Web), then we’d better to explicitly visualize these dependencies (and optionally auto generate the module documentation for that).

Imagine, if the Model Editor for the DevExpress eXpressApp Framework (XAF) supported this bit of functionality. Wouldn’t it make the task of writing and managing the extension modules just a little bit easier?

PS: Next posts within autofac and xLim 2 series could be on MockContainer implementation or on the problems of running xLim server under Mono. We’ll see how the research and development goes.

Managing the flexibility

Basically the capabilities of any given xLim 2.0 application are defined by the modules that have been loaded. Modules, when they are loaded, can do all sorts of complex things with .NET code:

  • Register business objects.
  • Register new components with different scopes, ownership, registration procedures (lambda, factory, reflection, instance etc)
  • Resolve components registered by other modules and augment them.

We do not care about the specifics as long as the IoC takes care of the registration/resolution and the modules do not break the system.

However, in order to configure the application, we need to know what building-blocks do we get after some modules get loaded (including all the modules they depend on).

This can be simply done by loading the desired assemblies into the IoC and then examining the actual results:

xLim Schema Manager

Additionally the modules can optionally provide some configuration presets for their components. These presets are merged into a single composite schema (basically just a class that is registered in the IoC by the SharedCoreModule that contains all the common functionality) and are also trivial to inspect and validate.

xLim Schema Manager

While we are at the schema level, we can also create our own configuration bits and save them to the configuration file for the specific application host.

Additionally, since the container has been actually loaded, we can check out how ViewSchemas would actually look when loaded by the desktop detail/grid views, or how command links would merge together into Ribbon/Bars in different combinations. Basic validation testing also happens here.

The third level of the configuration is creation of the actual navigation tree. It would reference the configured handlers (optionally overriding some parameters) to build the UI for the Web/Desktop users. This piece is done by the small console client, that connects to the running xLim server as the root user and builds the tree.

Users from the SuperAdmin group normally get the desktop view to modify the existing tree on-the-fly, but it is rarely used and kept only for the situations where it is urgently needed to reconfigure the production system (i.e.: allow manager to edit some fields, disable the workflow rules for some customer, add commands to the menu of the low-level user etc).

PS: the next post describes IoC Container Inspector functionality (logic behind the “Loaded Modules” bit) in detail.

One more usage of scopes and micro-controllers in composite applications

This post does not belong to the primary body of knowledge within autofac or xLim series.

It expands on the last article about IoC scopes and application composition and attempts to provide quick proof of concept answer (POC) to one question from the DevExpress Forum on XAF about implementing security scenarios.

Let’s talk code:

public sealed class ContextSecurityController : ICommand
{
  private readonly GridParameters _parameters;
  private readonly IIdentityObject _parentObject;
  private readonly IGuidIdentity _user;

  public ContextSecurityController(GridParameters parameters,
    IIdentityObject parentObject, IGuidIdentity user)
  {
    _parameters = parameters;
    _user = user;
    _parentObject = parentObject;
  }

  public void Execute()
  {
    string s = _parameters.CriteriaString;
    if (!string.IsNullOrEmpty(s) && s.Contains("#{"))
    {
      _parameters.CriteriaString = s
        .Replace("#{AccountId}", _user.Id.ToString())
        .Replace("#{ActorId}", _user.Owner.ToString())
        .Replace("#{ParentObjectId}", _parentObject.Oid.ToString());
    }
  }
}

In this scenario this controller should be resolved in the view scope and executed once (yes, it has the ICommand interface, since it is just a command). Upon execution it attempts to parse the XPO criteria string and modify it a little bit.

Here are the steps to make this work within the current xLim concept:

  • Add a comma-delimited list of start-up command names to the base ViewParameter object
  • Add 3 lines of code to the base view object when it loads the parameters (string.Split(Current.StartupCommands) - foreach - ResolveByName - Execute)
  • Configure the views to call this command/controller on startup.
  • Make sure that the views, dealing with the data, pass the instance of the parent object to the scope
  • Make sure that all the BOs inherit from IIdentityObject (I always do this, since this helps to provide ability to bind memos, documents, forms etc to any object in the system)

Then you could use criteria strings like:

  • Document.CreatedByOid=#{AccountId}
  • Employer.Manager.Oid=#{ParentObjectId}

Side effects:

  • Any desktop or web view will get the ability to have configurable commands executed on the start-up (commands normally do not care about the UI)
  • Since any application already has a huge list of commands in the library, you could re-use these, too.

This controller is extremely simple to extend with the support for more complex tokens (i.e.: #{DateTime}, #{CurrentOfficeId}, #{SecurityHash} etc), you just need to make sure that the values do not mess up the syntax of XPO. Or you could implement more complex parser that takes the named object from the current scope and evaluate some property of it. You’ll get the simplified scripting in that case.

One more option is to use the DSLs to express complex business requirements (although, I would not advise to do that).

PS: This approach seems to be simple and flexible, and yet it is not recommended for the xLim 2 implementations. Too much of flexibility in the wrong spot is not a good thing for the project in the long term (been there, done that). This post serves POC purpose only.

How to use IoC container with nested scopes for application composition?

Well, that’s simple. The idea itself comes from the CAB.

Basically you can organize your application (whether it is a desktop client, an automation engine, web UI or something else) in such a manner:

Sample Application Scopes

This sample desktop application is logically organized into the nested scopes (or contexts or containers).

The Application Scope is the top-most. It contains component registrations that are associated with the entire application (user identity, service for displaying nice message boxes, navigation service, data layer, different commands, etc). The components are accessible by any child scope.

Let’s say that the application consists of workspaces (just like in cab) that are designed to hold views (i.e.: tabbed workspace displays views in tabs, window workspace creates a separate window for each view, etc). Workspaces can declare their own scopes that could hold items common to all views within.

Then, every view could have one more scope that contains components specific to this view.

What’s the point of that?

Well, this is simple. Imagine, that you follow the command pattern and encapsulate specific actions (i.e. delete record, add record, print grid, export grid etc) in separate command classes. And you register these classes by name within the Application scope, since you want to be able to access them from any scope.

Simplified example of such command would be:

public sealed class DeleteSelectedRecords : ICommand
{
  private readonly ISession _session;
  private readonly IRecordSelector _selector;
  private readonly IMessageBoxService _messaging;

  public DeleteSelectedRecords(IRecordSelector selector, ISession session,
    IMessageBoxService messaging)
  {
    _session = session;
    _selector = selector;
    _messaging = messaging;
  }

  public void Execute()
  {
    if (_messaging.Ask("Are you sure about that?") == MessageCode.OK)
    {
      _session.Delete(selector.GetRecords());
    }
  }
}

Now:

  • If you resolve this command in the scope of some GridView view (i.e. viewScope.ResolveByName), the appropriate constructor parameters will be populated automatically.
  • IRecordSelector and ISession are pulled from the current context while IMessageBoxService belongs to the entire application (and the instance is declared only there).
  • The command is reusable in any scope that has these three components.
  • This specific command is stateless and can be reused. So if it was registered with the container ownership and scope, then the first request will create the command within the container, fill it with the dependencies and return the instance. All subsequent requests will merely return the existing command.
  • Since the commands are referenced by name, it is easy to replace or customize any single command specifically.
  • It is possible to override some behavior in the nested containers simply by declaring override instance of some component. For example, if you need to open views in specific workspace with the access rights of the guest account (i.e. for preview), then simply add IUserIdentity for the guest into that workspace. And all commands that use this component will get the override.
  • How do you add completely new command to an existing view in this simplified situation?
    • Code in some ICommand implementation.
    • Register that command within the Application Scope with some name (you do register components via configs, do not you?).
    • Add the name of the command to the list of commands that could be called by the specific view (you keep that in configs, too, do not you?)
    • Sit back and relax. The rest will be done by the IoC container and the view.
  • The scenario above is a bit simplified. I’ve skipped the command registration (command links) within the menus in a menu-invariant manner (whether it is a global Ribbon with dynamic tabs, local group within BarManager or something else).
  • The scenario above can be implemented without touching the original codebase. You just need to reference one more assembly and then tweak the settings.
  • ICommand is just one example. You could also register other components (i.e.: IView, ITranslator, IWorkflow, IController etc) in similar manner. Every specific usage scenario could have its specifics, yet the common benefits are shared.
  • All scope-related components will be disposed when the container is disposed.
  • Your IoC container has to support the proper nested scopes and determenistic disposal, in order to pull these tricks. Autofac does that.
  • That’s how it is advised to be done for the current implementations of xLim 2.

PS: How many LOCs would you have in your unit test fixture for the single “DeleteSelectedRecords” command? One of the later posts in these series will address the issue of dealing with this honorable task efficiently. Stay tuned.

xLim portability issues

As you know, one of the long-term “nice-to-have”s of the xLim 2 architecture is the ability to run web/server/desktop/engine pieces under the Mono environment (and this would open new OSes as targetable platforms).

Given the dependencies of the current xLim version, efficient desktop cross-platform compatibility for desktop client apps is yet out of the reach:

  • DevExperience WinForms components are never to run under Mono (heavy PInvoke dependencies are the payment for the beautiful UI). Try running MoMA to see that yourself. Although I would really miss only the XtraGrids piece (and these have a decent chance of being re-implemented under Silverlight).
  • Pure GTK# and WinForms client apps could do the trick but they neither feel nor they are efficient to use.
  • The best long-shot would be the WPF-based architecture with the cross-platform support for the Silverlight (or full-blown WPF) UI, but this is yet to come (and there’s still some uncertainty with that)

So we have web/server/engine pieces that could be made Mono-compatible in the mid-term. The situation is good with these. Mono web servers successfully host ASP.NET starter kits and different web services. And if DevExperience.Web has some portability issues, then it could be ditched. The only piece that I would really miss is the grid again (and there’s that “Silverlight-to-the-rescue” thing again).

Services and remoting do work under Mono with some quirks (binary compatibility for the cross-platform remoting is there also), although GC for now might be far from being perfect.

There are two major obstacles on this way (and they come from the major dependencies):

  • Autofac IoC compatibility with Mono
  • XPO compatibility with Mono

Luckily autofac is almost there (there are just some tests that fail under Mono).

XPO is in worse shape. It does not run at all. Luckily Mono Migration analyzer does not have a lot of arguments with the XPO code (some of these could be completely ignored).

Well, we’ll see. The good thing with the “nice-to-haves” is that they deal with the future probabilities and thus their effect on the present architecture is rather flexible.

PS: If you are interested about the reasoning behind the business need for cross-platform support xLim, then you might want to check these posts: