Last active
August 29, 2015 13:56
-
-
Save glennblock/8888901 to your computer and use it in GitHub Desktop.
Script packs as script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WebApi : IScriptPackContext { | |
public WebApi(ILog logger, IControllerTypeManager typeManager) { | |
... | |
} | |
} | |
public class WebApiScriptPack : IScriptPack | |
{ | |
private readonly ILog _logger; | |
private readonly IControllerTypeManager _typeManager; | |
[ImportingConstructor] | |
public ScriptPack(ILog logger, IControllerTypeManager typeManager) | |
{ | |
_logger = logger; | |
_typeManager = typeManager; | |
} | |
IScriptPackContext IScriptPack.GetContext() | |
{ | |
return new WebApi(_logger, _typeManager); | |
} | |
void IScriptPack.Initialize(IScriptPackSession session) | |
{ | |
session.AddReference("System.Net.Http"); | |
var namespaces = new[] | |
{ | |
"System.Web.Http", | |
"System.Web.Http.SelfHost", | |
"System.Web.Http.Dispatcher", | |
"Owin" | |
}.ToList(); | |
namespaces.ForEach(session.ImportNamespace); | |
} | |
void IScriptPack.Terminate() | |
{ | |
} | |
} | |
ScriptPack<WebApiScriptPack>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Code that the author writes, no need to implement an IScriptPack! | |
ScriptPack<WebApi>() | |
.References("System.Net.Http") | |
.Namespaces("System.Web.Http", "System.Web.Http.SelfHost", "System.Web.Http.Dispatcher"); | |
public class WebApi { | |
public WebApi(ILog logger, IControllerTypeManager typeManager, IRequirer requirer) { | |
... | |
} | |
} |
Does WebApi
still have to implement IScriptPackContext
?
yes
Even with the scripty way? Why would it need to?
BTW - the scripty way looks awesome.
I would like it to work like this, so I don't need to write the complete path each time.
ScriptPack<WebApi>()
.References("System.Net.Http")
.From("System.Web.Http").Use(".", "SelfHost", "Dispatcher");
// or
ScriptPack<WebApi>()
.References("System.Net.Http")
.From("System.Web.Http").Using(".", "SelfHost", "Dispatcher");
The "."
seems like overkill, but could give a better undestanding of what we try to use.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting idea here would be if you just use "using" and "#r" instead of the "AddXXX" methods. Need to think about.