github twitter linkedin email
Look – Orleans and Nancy
Jun 14, 2015
One minute read

So this happened:

The grain:

public class Grain1 : Grain, IGrain1
{
    private int _counter;

    public Task SayHello()
    {
        _counter ++;

        return Task.FromResult("Hello from Orleans.  You have asked me " + _counter + " times!");
    }
}

General setup for now is this:

The web application is Nancy

public class HelloModule : NancyModule
{
    public HelloModule()
    {
        Get["/", true] = async (x, ct) =>
        {
            var hello = Orleans.GrainFactory.GetGrain<IGrain1>(Guid.Empty)
                .SayHello();

            return await hello;
        };

    }
}

One catch for me was the client initialization – I had to resort to telling the Web application *exactly* where the client config was.

public class OrleansInitializaiton : NancyModule
{
    public OrleansInitializaiton()
    {
        var clientConfigFile = new FileInfo(Path.Combine(GetAssemblyPath(), "ClientConfiguration.xml"));
        Orleans.GrainClient.Initialize(clientConfigFile);
    }

    private static string GetAssemblyPath()
    {
        return Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
    }
}

Next Steps:

  • Push to public github repo
  • Do something interesting with CQRS / Event Sourcing
  • Publish to Azure

Tags: orleans

Back to posts