1

I am trying to add Scriptcs support to an ASP.NET MVC application. I have a ScriptServices inspired by https://github.com/filipw/Glimpse.ScriptCs/blob/master/Glimpse.ScriptCs/ScriptCsHost.cs.

In my controller, I have a working simple that looks like this

var host = new ScriptCsHost();
host.Root.Executor.Initialize(new[] { "System.Web"}, new IScriptPack[0]);

var code = "var x=5; x==5";

var result = host.Root.Executor.ExecuteScript(code, new string[0]);
host.Root.Executor.Terminate();

return Content(result.ReturnValue.ToString());

This works fine. I want the code executed to be able to to use some of the repositories that get injected to the controller (e.g private readonly CustomerRpository _customerRepository). Is there a way to do that?

Igor Kulman
  • 16,211
  • 10
  • 57
  • 118
  • From what I gather from [their website](http://scriptcs.net/), `scriptcs` lets you input a code string that gets compiled into a separate assembly and is run. In order to pass object references to that code from the code calling it, you'll either need some interop between your running code and the generated code, or the `ScriptCsHost` needs to allow the injection of arbitrary variables upon startup. Does `scriptcs` have documentation, can you show a code example of what exactly you need? – CodeCaster Nov 06 '13 at 09:48

1 Answers1

0

Solved using "plain" Roslyn instead of Scriptcs. In Roslyn you can add any object to the session.

Igor Kulman
  • 16,211
  • 10
  • 57
  • 118
  • if you use this build of scriptcs you can too https://github.com/filipw/scriptcs/tree/roslyn-host. It's coming to the core, see the PR https://github.com/scriptcs/scriptcs/pull/508 – Filip W Nov 11 '13 at 11:12