Frage

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?

War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top