有人可以建议我在Unity3D中运行一个好的,轻巧的c#IoC容器,而不依赖于服务定位器模式吗?谢谢!
在过去,我使用swiftsuspenders作为动作脚本3 IoC控制器.基本上,switfsuspender的第一个版本与Ninject内核类似,称为注入器.
如果我想创建一个应用程序注入器(假设在整个应用程序中使用最相关的映射),我必须在应用程序类中注入注入器本身.
我想知道现在在应用程序的几个类中使用kernel.get <>的做法是什么.我应该注入内核吗?
我个人更喜欢使用kernel.inject但是如果我可以做kernel.inject我真的可能会手动注入依赖项,这可能更好(亲吻).
测试用例很好,但它们远非实际的实际问题,所以我希望你能帮助我澄清这一点.谢谢.
编辑:我注意到有些人谈论"根容器",似乎这是我正在寻找的概念.我应该如何设置根容器并让其他应用程序类知道它?
Edit2示例代码(请原谅错误,这只是为了示例):
class SomeClass
{
public SomeClass()
{
Command cmd = new Command();
cmd.execute();
}
}
class SomeOtherClass:ISomeOtherClass
{
public void allright()
{
//right
}
}
class Command
{
ISomeOtherClass dependency;
void execute()
{
dependency.allright();
}
}
Program.Main()
{
IKernel kernel = new StandardKernel();
kernel.Bind<SomeClass>().ToSelf().InSingletonScope();
kernel.Bind<ISomeOtherClass>().To<SomeOtherClass>();
SomeClass sc = kernel.Get<SomeClass>();
}
Run Code Online (Sandbox Code Playgroud)
我还没有对此进行测试,因为我仍然在解决一些初始化问题,但我的问题是,命令类如何知道SomeOtherClass?我目前的假设是在SomeClass中注入内核并使用Inject方法.
我知道其他人写了类似的问题,但我认为我的情况不同,因为我找不到任何解决方案.
我有一个对象赋值,这个非常简单:
_buffer3 = buffer; //they are just simple reference types
Run Code Online (Sandbox Code Playgroud)
生成的汇编代码如下
mov edx,dword ptr [ebp-3Ch]
mov eax,dword ptr [ebp-40h]
lea edx,[edx+4]
call 69C322F0
Run Code Online (Sandbox Code Playgroud)
现在,只是为了理解发生了什么,我想进入呼叫(为什么要在分配中使用呼叫?).但是,该地址的代码不存在,我无法介入.如果我在地址代码字段中键入地址,那就是显示的内容:
69C322F0 ???
Run Code Online (Sandbox Code Playgroud)
试图解决这个问题的任何帮助?:)
编辑..显然,当在类的方法内分配引用时,会添加神秘的调用.
如果我有这个课程:
private class Test
{
int _X;
int _Y;
Test _t;
public void SetValues(int x, int y, Test t)
{
_X = x;
_Y = y;
}
}
Run Code Online (Sandbox Code Playgroud)
为方法SetValues生成的程序集是:
_X = x;
00000028 mov eax,dword ptr [ebp-3Ch]
0000002b mov edx,dword ptr [ebp-40h]
0000002e mov dword ptr [eax+8],edx
_Y = y;
00000031 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 WinDbg 调试单声道应用程序。该应用程序在 WinDbg 无法在内部解码的 C# 代码中处于无限循环中。
我知道我可以使用该函数mono_pmip()将堆栈地址转换为该函数的名称
我正在使用.call mono!mono_pmip(0x63a0630)(使用验证为可用x *!*pmip*),但我仍然无法获得该函数的输出,而是收到了访问冲突。
这是堆栈:
34 018feee8 071824eb 0x71824eb
35 018fef08 07181f4c 0x71824eb
36 018fef28 0717fd8a 0x7181f4c
37 018fef68 071708ae 0x717fd8a
38 018fefc8 07170328 0x71708ae
39 018ff078 0716efa5 0x7170328
3a 018ff0e8 0716ed4c 0x716efa5
3b 018ff108 18de8f88 0x716ed4c
3c 018ff1b8 18de75ff 0x18de8f88
3d 018ff208 18de6f6f 0x18de75ff
3e 018ff238 18de660c 0x18de6f6f
3f 018ff2f8 18de60ce 0x18de660c
40 018ff328 18de6033 0x18de60ce
41 018ff348 18ddf586 0x18de6033
42 018ff3e8 18ddebc6 0x18ddf586
43 018ff408 …Run Code Online (Sandbox Code Playgroud) 我确信有一个简单的答案,但经过一些研究后我找不到它.我阅读并证明(除非我写的是错误的)自动编组通过托管内存中分配的引用(或类)传递的结构,由本机代码正确读取和写入,但是一旦代码执行返回到托管层,不保留本机代码中更改的值.这是一个例子:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class DirtyWordsCheckResult
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string replace_string;
public EnumDirtyWordsType dirty_type;
public DirtyWordsCheckResult()
{
replace_string = new string(' ', 1024);
}
}
public enum EnumDirtyWordsType
{
kDirtyWordsTypeNormalAllowWords = 0, // normal allow words
kDirtyWordsTypeEvil = 1, // illegal,can not be displayed
kDirtyWordsTypeSensitive = 2, // legal, but contain sensitive
}
public override EResult DirtyWordsFilter(string words, bool replace_sensitive, out DirtyWordsCheckResult check_result)
{
check_result = new DirtyWordsCheckResult();
var result = Utils.DirtyWordsFilter(utils_, words, replace_sensitive, check_result); …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种数据结构,它可以确保至少删除和插入节点的Log(n)复杂度以及接近O(1)或分摊的Log(n)以搜索最大(或最小)值.
我正在考虑使用自我平衡的BST(哪一个?)进行修改以记住插入的最大值(或最小值).
有什么建议吗?
对不起,我必须编辑问题...当然,自平衡BST可以允许在log(n)中搜索max和min,但我正在考虑更多关于O(1)的事情.
c# ×2
algorithm ×1
assembly ×1
debugging ×1
marshalling ×1
mono ×1
native-code ×1
ninject ×1
ninject-2 ×1
windbg ×1