本文整理汇总了C#中StandardKernel.Unbind方法的典型用法代码示例。如果您正苦于以下问题:C# StandardKernel.Unbind方法的具体用法?C# StandardKernel.Unbind怎么用?C# StandardKernel.Unbind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StandardKernel
的用法示例。
在下文中一共展示了StandardKernel.Unbind方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreationWillFailIfAllDepenciesAreMissingAndInjectAttributeIsApplied
public void CreationWillFailIfAllDepenciesAreMissingAndInjectAttributeIsApplied()
{
using ( IKernel kernel = new StandardKernel() )
{
kernel.Bind<NinjaBarracks>().ToSelf();
Assert.Throws<ActivationException>( () => kernel.Get<NinjaBarracks>() );
kernel.Bind<IWeapon>().To<Sword>();
Assert.Throws<ActivationException>( () => kernel.Get<NinjaBarracks>() );
kernel.Unbind<IWeapon>();
kernel.Bind<IWarrior>().To<Samurai>();
Assert.Throws<ActivationException>( () => kernel.Get<NinjaBarracks>() );
kernel.Unbind<IWarrior>();
}
}
示例2: BuiltinCompile
/// <summary>
/// Compiles the built-in embedded resources.
/// </summary>
private static void BuiltinCompile()
{
// Create kernel.
var kernel = new StandardKernel();
kernel.Load<ProtogameAssetIoCModule>();
kernel.Load<ProtogameScriptIoCModule>();
var services = new GameServiceContainer();
var assetContentManager = new AssetContentManager(services);
kernel.Bind<IAssetContentManager>().ToMethod(x => assetContentManager);
kernel.Bind<IRenderBatcher>().To<NullRenderBatcher>();
// Only allow source and raw load strategies.
kernel.Unbind<ILoadStrategy>();
kernel.Bind<ILoadStrategy>().To<LocalSourceLoadStrategy>();
var assetModule = new ProtogameAssetIoCModule();
assetModule.LoadRawAssetStrategies(kernel);
// Set up remaining bindings.
kernel.Bind<IAssetCleanup>().To<DefaultAssetCleanup>();
kernel.Bind<IAssetOutOfDateCalculator>().To<DefaultAssetOutOfDateCalculator>();
kernel.Bind<IAssetCompilationEngine>().To<DefaultAssetCompilationEngine>();
// Rebind for builtin compilation.
kernel.Rebind<IRawAssetLoader>().To<BuiltinRawAssetLoader>();
// Set up the compiled asset saver.
var compiledAssetSaver = new CompiledAssetSaver();
// Retrieve the asset manager.
var assetManager = kernel.Get<LocalAssetManager>();
assetManager.AllowSourceOnly = true;
assetManager.SkipCompilation = true;
// Retrieve the transparent asset compiler.
var assetCompiler = kernel.Get<ITransparentAssetCompiler>();
// Retrieve all of the asset savers.
var savers = kernel.GetAll<IAssetSaver>();
var rawLoader = kernel.Get<IRawAssetLoader>();
// For each of the platforms, perform the compilation of assets.
foreach (var platformName in new[]
{
"Android",
"iOS",
"Linux",
"MacOSX",
"Ouya",
"Windows",
})
{
Console.WriteLine("Starting compilation for " + platformName);
var platform = (TargetPlatform)Enum.Parse(typeof(TargetPlatform), platformName);
var outputPath = Environment.CurrentDirectory;
assetManager.RescanAssets();
// Create the output directory if it doesn't exist.
if (!Directory.Exists(outputPath))
{
Directory.CreateDirectory(outputPath);
}
// Get a list of asset names that we need to recompile for this platform.
var assetNames = rawLoader.ScanRawAssets();
foreach (var asset in assetNames.Select(assetManager.GetUnresolved))
{
Console.Write("Compiling " + asset.Name + " for " + platform + "... ");
try
{
assetCompiler.HandlePlatform(asset, platform, true);
foreach (var saver in savers)
{
var canSave = false;
try
{
canSave = saver.CanHandle(asset);
}
catch (Exception)
{
}
if (canSave)
{
try
{
var result = saver.Handle(asset, AssetTarget.CompiledFile);
compiledAssetSaver.SaveCompiledAsset(
outputPath,
asset.Name,
result,
result is CompiledAsset,
platformName);
Console.WriteLine("done.");
break;
//.........这里部分代码省略.........
示例3: BulkCompile
private static void BulkCompile(List<string> assemblies, List<string> platforms, string output)
{
// Create kernel.
var kernel = new StandardKernel();
kernel.Load<ProtogameAssetIoCModule>();
kernel.Load<ProtogameScriptIoCModule>();
var services = new GameServiceContainer();
var assetContentManager = new AssetContentManager(services);
kernel.Bind<IAssetContentManager>().ToMethod(x => assetContentManager);
kernel.Bind<IRenderBatcher>().To<NullRenderBatcher>();
// Only allow source and raw load strategies.
kernel.Unbind<ILoadStrategy>();
kernel.Bind<ILoadStrategy>().To<LocalSourceLoadStrategy>();
var assetModule = new ProtogameAssetIoCModule();
assetModule.LoadRawAssetStrategies(kernel);
// The assembly load strategy is required for references.
// Assets loaded with the assembly load strategy won't have
// any savers defined, so they won't ever get processed.
kernel.Bind<ILoadStrategy>().To<AssemblyLoadStrategy>();
// Load additional assemblies.
foreach (var filename in assemblies)
{
var file = new FileInfo(filename);
try
{
var assembly = Assembly.LoadFrom(file.FullName);
foreach (var type in assembly.GetTypes())
{
try
{
if (type.IsAbstract || type.IsInterface)
continue;
if (type.Assembly == typeof(FontAsset).Assembly)
continue;
if (typeof(IAssetLoader).IsAssignableFrom(type))
{
Console.WriteLine("Binding IAssetLoader: " + type.Name);
kernel.Bind<IAssetLoader>().To(type);
}
if (typeof(IAssetSaver).IsAssignableFrom(type))
{
Console.WriteLine("Binding IAssetSaver: " + type.Name);
kernel.Bind<IAssetSaver>().To(type);
}
if (type.GetInterfaces().Any(x => x.Name == "IAssetCompiler`1"))
{
Console.WriteLine("Binding IAssetCompiler<>: " + type.Name);
kernel.Bind(type.GetInterfaces().First(x => x.Name == "IAssetCompiler`1")).To(type);
}
if (typeof(ILoadStrategy).IsAssignableFrom(type))
{
Console.WriteLine("Binding ILoadStrategy: " + type.Name);
kernel.Bind<ILoadStrategy>().To(type);
}
}
catch
{
// Might not be able to load the assembly, so just skip over it.
}
}
}
catch (Exception)
{
Console.WriteLine("Can't load " + file.Name);
}
}
// Set up remaining bindings.
kernel.Bind<IAssetCleanup>().To<DefaultAssetCleanup>();
kernel.Bind<IAssetOutOfDateCalculator>().To<DefaultAssetOutOfDateCalculator>();
kernel.Bind<IAssetCompilationEngine>().To<DefaultAssetCompilationEngine>();
// Get the asset compilation engine.
var compilationEngine = kernel.Get<IAssetCompilationEngine>();
compilationEngine.Execute(platforms, output);
}