Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Repository files navigation

Licence Apache 2Build statusCoverage statusNuGet

Project icon

ScriptCs.ComponentModel.Composition

Add a ScriptCsCatalog which can be used to add some ScriptCs scripts to a MEF container.

Usage

Simply create a new ScriptCsCatalog and use it in your MEF composition:

// You can add script by script//var catalog = new ScriptCsCatalog(new[] { "ScriptA.csx", "ScriptB.csx" });// Or an entire foldervarcatalog=newScriptCsCatalog("Scripts");varcontainer=newCompositionContainer(catalog);varbatch=newCompositionBatch();batch.AddPart(this);container.Compose(batch);

Add References

It can be useful to add a references to all scripts loaded by the ScriptCsCatalog. For example, you provide the interface IGreeter for imports in MEF. So a basic script should be:

#r "Greeter.Contracts.dll"usingGreeter.Contracts;publicclassMyGreeter:IGreeter{
...}

But you can pass the IGreeter type as reference to the ScriptCsCatalog:

// You can add script by scriptvarcatalog=newScriptCsCatalog(new[]{"ScriptA.csx","ScriptB.csx"},newScriptCsCatalogOptions{References=new[]{typeof(IGreeter)}});// Or an entire foldervarcatalog=newScriptCsCatalog("Scripts",newScriptCsCatalogOptions{References=new[]typeof(IGreeter)}});

And the script will become:

publicclassMyGreeter:IGreeter{
...}

Script args

It is also possible to passes arguments to the script with the ScriptArgs property of the options:

varcatalog=newScriptCsCatalog("Scripts",newScriptCsCatalogOptions{ScriptArgs=new[]{"-loglevel","INFO"}});

It can be helpful with the use of Script Packs.

Script Packs

Script Packs can be used, the location varies depending on the approach used:

  • script by script: the packages location is the current directory of your application
  • folder: the packages location is the folder specified

Load script one by one

By default all scripts are loaded in one file to be interpreted by ScriptCS, but it can be source of issues like when alias are used.

The KeepScriptsSeparated option allow to load script one by one and remove these issues:

varcatalog=newScriptCsCatalog("Scripts",newScriptCsCatalogOptions{KeepScriptsSeparated=true});

Contributors

Thanks to Glenn Block Script Packs can be used!
Thanks to beolutz for the custom file system support and KeepScriptsSeparated option.

About

A MEF catalog that allows authoring parts as scripts

Topics

Resources

Stars

5 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages