-
Notifications
You must be signed in to change notification settings - Fork 369
Hosting
You can host scriptcs within your own custom applications / and components whether they are running on .NET or Mono.
You can download a simple example illustrating how to host scriptcs within a console app here.
Within scriptcs your scripts can access ambient members like Env
which are surfaced via the ScriptHost
object. You can also create a custom script host which exposes additional members to scripts running in your custom hosted environment. For example you may want to add additional properties or members.
Here are the steps to create and register a custom host:
- Create a custom host class which derives from
ScriptHost
. Add whatever properties or methods you'd like to this object. They will project into the scripting environment as ambient members similar toEnv
. - Create a custom
ScriptHostFactory
which returns your host. - Register this factory using the
ScriptCsServicesBuilder.ScriptHostFactory<T>()
method where T is your factory. Do this before callingBuild
on the builder.
That should be it. Within your scripts / the REPL (if you are hosting the REPL) you should be able to access the new members.
There are several projects which leverage scriptcs hosting in the box.
-
scriptcs-rebus uses the scriptcs hosting layer to allow executing scripts that are sent as message payloads. This post illustrates how [@madstt] (https://twitter.com/madstt) used the hosting library within the
ScriptCs.Rebus
package. - Glimpse.ScriptCs uses the scriptcs [hosting layer] (https://github.com/filipw/Glimpse.ScriptCs/blob/master/Glimpse.ScriptCs/ScriptCsHost.cs) to execute scripts within Glimpse. This post discusses the approach.
-
samples-scriptcs-webhost illustrates a sample API which accepts a script in the payload and executes it. It introduces a
ScriptController
which invokes scriptcs. - scriptcs-owin-host-iis uses scriptcs for allowing authoring of OWIN applications as scripts. These apps can also be hosted on IIS using Helios.
- Home
- Build scriptcs
- Building on Mac and Linux
- Using scriptcs
- The command line
- Package installation
- Writing a script
- Compiling (and caching) to a .dll
- Debugging a script
- REPL
- Running scripts in Atom
- REPL
- Script Packs
- Script Libraries
- Modules
- Hosting
- Community
- Known Issues