我想了解如何解决MVC4应用程序中的统一命名类型注册。
我正在使用“ Unity 3.0”和“ ASP.NET MVC的Unity Boostrapper”。
我了解到Unity已在DependencyResolver中注册,因此我可以使用依赖项解析器方法来获取已注册类型的实例。
当我想找回简单的注册时,此方法很好用。
例如
//Registration
container.RegisterType<IFootballer, VanPersey>();
//Instantiation
var footballer1 = DependencyResolver.Current.GetService<IFootballer>();
Run Code Online (Sandbox Code Playgroud)
但是在某些情况下,当我想获取对命名类型注册的引用时,似乎IDependencyResolver接口没有提供适当的方法来获取命名类型注册实例。
如果我可以直接访问unity容器,则可以执行以下操作:
//Registration
container.RegisterType<IFootballer, VanPersey>("Attacker" );
container.RegisterType<IFootballer, NemanjaVidic>("Defender");
//Instantiation
unityContainer.Resolve<IFootballer, Footballer>("Attacker")
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,为了获得命名注册的实例,在MVC应用程序中使用unity的最合适方法是什么。即可以进入统一容器吗?
请注意,此问题不适用于任何生产实现,我正在研究Unity(以及首次使用IoC容器)并希望获得更好的理解。
我了解在生产中,我很可能会通过控制器构造函数传递依赖关系,这实际上使我想到了另一个问题。
在以下示例中,使用控制器构造函数注入时,如何指示要解析的命名类型:
//Registration
container.RegisterType<IFootballer, VanPersey>("Attacker" );
container.RegisterType<IFootballer, NemanjaVidic>("Defender");
//Instantiation
public HomeController(IFootballer footballer)
Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc ioc-container inversion-of-control unity-container
对于我的项目之一,我需要导入一个非常大的文本文件(~950MB).我正在为我的项目使用Symfony2和Doctrine 2.
我的问题是我得到的错误如下:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 24 bytes)
Run Code Online (Sandbox Code Playgroud)
如果我将内存限制增加到1GB,甚至会出现错误.
我试图通过使用XDebug和KCacheGrind(作为PHPEdit的一部分)来分析问题,但我真的不明白这些值:(
我正在寻找一种工具或方法(Quick and Simple,因为我没有太多时间)来找出为什么分配内存而不是再次释放.
编辑
要清除这里的一些内容,我的代码是:
$handle = fopen($geonameBasePath . 'allCountries.txt','r');
$i = 0;
$batchSize = 100;
if($handle) {
while (($buffer = fgets($handle,16384)) !== false) {
if( $buffer[0] == '#') //skip comments
continue;
//split parts
$parts = explode("\t",$buffer);
if( $parts[6] != 'P')
continue;
if( $i%$batchSize == 0 ) {
echo 'Flush & Clear' . PHP_EOL;
$em->flush();
$em->clear();
}
$entity = $em->getRepository('MyApplicationBundle:City')->findOneByGeonameId( $parts[0] …Run Code Online (Sandbox Code Playgroud) 在android中做了一个应用程序,后退按钮也被处理,就像一个网站?
如果是这样,这些按钮被编程为任何按钮或它们是否是所有应用程序的默认按钮?
谢谢...
System.out.println("\n What is the chemical symbol for water\n 1.HO2 \n 2.H20 \n 3.OOH \n 4. O2H");
b = input.nextInt();
if (b==2) {
B=20;
}
else if (b != 2) {
B=0;
}
**total= A+B;**
switch (total) {
case 40:
System.out.println("WOW You scored 40/40, you sure know your science");
break;
case 20:
System.out.println("Meh,20/40.");
break;
case 0:
System.out.println("0/40 Better luck next time!");
break;
}
Run Code Online (Sandbox Code Playgroud)
我正在制作一个简单的mcq练习应用程序,它将根据正确答案的数量对用户进行评分.我用if if根据答案给出整数'A'和'B'值.但它给我的错误,在总= A + B是一个 (A已在前面的,如果类似这样的语句被初始化)和乙尚未初始化.任何解决方案 请原谅我一个不高兴的人
当我提到
char operator;
Run Code Online (Sandbox Code Playgroud)
它给出了c#中预期的一元运算符错误.
所以当它提到extern时,android中的默认值是'\ u0000'
c# ×2
android ×1
asp.net-mvc ×1
character ×1
declaration ×1
doctrine-orm ×1
eclipse ×1
if-statement ×1
java ×1
kcachegrind ×1
php ×1
symfony ×1
xdebug ×1