how to hook into orchard services

Jun 9, 2013 at 5:58 PM
Hi guys.
Like the scripting engine.
Can i call orchard services within my c# script ?
Any examples ?
I tried calling on Orchard.WorkContext.CurrentSite.SiteName; but it failed.

using System;
using Orchard;

public class DotNetScripting
public static dynamic Main()
    return Greeting();

public static string Greeting()
    return Orchard.WorkContext.CurrentSite.SiteName;

Jun 9, 2013 at 6:53 PM
Hi Yiannis!

These services are not yet available, but it's on the list, coming soon! :)
Jun 9, 2013 at 7:07 PM
But since the scripting engine exposes events, you can write a small event handler and inject the WorkContext yourself: you could use BeforeExecution to add a variable containing the WorkContext to the scope.
Jun 9, 2013 at 7:29 PM
Thanks guys.
I'll check out Piedones tip , see how it goes.
Jun 9, 2013 at 7:48 PM
I added this line in the DefaultAssemblyLoader class just after the loading of assemblies
public void BeforeExecution(BeforeExecutionContext context)
            var scope = context.Scope;
            scope.LoadAssembly(typeof(string).Assembly); // mscorlib.dll
            scope.LoadAssembly(typeof(Uri).Assembly); // System.dll
            scope.LoadAssembly(typeof(HttpContext).Assembly); // System.Web.dll
            scope.LoadAssembly(typeof(AjaxHelper).Assembly); // System.Web.Mvc.dll
            scope.LoadAssembly(typeof(Shapes).Assembly); // Orchard Core
            scope.LoadAssembly(typeof(WorkContext).Assembly); // Orchard Framework
           //yiannis code
            scope.SetVariable("OrchardServices", _orchardServices);
I then tried calling the service from the script like this :
public static string Greeting()
    return OrchardServices.WorkContext.CurrentSite.SiteName;

but it did'nt work.

Am I missing something ?