对依赖注入很新,我试图弄清楚这是否是反模式.
假设我有3个组件:
Foo.Shared - this has all the interfaces
Foo.Users - references Foo.Shared
Foo.Payment - references Foo.Shared
Run Code Online (Sandbox Code Playgroud)
Foo.Users需要一个在Foo.Payment中构建的对象,而Foo.Payment也需要来自Foo.Users的东西.这会产生某种循环依赖.
我在Foo.Shared中定义了一个接口,代理我正在使用的依赖注入框架(在本例中为NInject).
public interface IDependencyResolver
{
T Get<T>();
}
Run Code Online (Sandbox Code Playgroud)
在容器应用程序中,我有一个这个接口的实现:
public class DependencyResolver:IDependencyResolver
{
private readonly IKernel _kernel;
public DependencyResolver(IKernel kernel)
{
_kernel = kernel;
}
public T Get<T>()
{
return _kernel.Get<T>();
}
}
Run Code Online (Sandbox Code Playgroud)
配置如下所示:
public class MyModule:StandardModule
{
public override void Load()
{
Bind<IDependencyResolver>().To<DependencyResolver>().WithArgument("kernel", Kernel);
Bind<Foo.Shared.ISomeType>().To<Foo.Payment.SomeType>(); // <- binding to different assembly
...
}
}
Run Code Online (Sandbox Code Playgroud)
这允许我Foo.Payment.SomeType从Foo.Users内部实例化一个新对象,而无需直接引用:
public class UserAccounts:IUserAccounts
{ …Run Code Online (Sandbox Code Playgroud) 我使用的是 ubuntu 9.10,我使用包管理器安装了 java 和 tomcat。当我去运行 startup.sh 时,它首先抱怨 catalina.out 不存在且不可写。我解决了这个问题,它没有抱怨(为什么不包含在安装中??)现在它抱怨当我关闭服务器时 server.xml 不在那里。这是我从命令行的输出:
user@desktop:/usr/share/tomcat6$ ./bin/startup.sh
Using CATALINA_BASE: /usr/share/tomcat6
Using CATALINA_HOME: /usr/share/tomcat6
Using CATALINA_TMPDIR: /usr/share/tomcat6/temp
Using JRE_HOME: /usr/lib/jvm/java-6-sun-1.6.0.15
user@desktop:/usr/share/tomcat6$ ./bin/shutdown.sh
Using CATALINA_BASE: /usr/share/tomcat6
Using CATALINA_HOME: /usr/share/tomcat6
Using CATALINA_TMPDIR: /usr/share/tomcat6/temp
Using JRE_HOME: /usr/lib/jvm/java-6-sun-1.6.0.15
Dec 11, 2009 4:42:57 PM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop:
java.io.FileNotFoundException: /usr/share/tomcat6/conf/server.xml (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:407)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:337)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)
user@desktop:/usr/share/tomcat6$
Run Code Online (Sandbox Code Playgroud)
我真的是 tomcat 的新手,所以这可能是一个愚蠢的问题,但为什么在全新安装的 …
我正在使用WPF开发一个应用程序.该应用程序全屏运行,无论显示器分辨率如何,我都需要它才能很好地调整大小.图形设计师为UI按钮,背景等设计了精美的图像.使用Illustrator插件,所有图像都已转换为xaml文件.我已将所有这些图像添加到应用程序中,它们看起来很棒.我也使用了很多Grid布局,以便屏幕可以在保持布局的同时调整大小.所有这些都根据需要显示,当以不同的分辨率运行时,没有任何东西看起来拉伸.但是,屏幕转换和UI交互很慢.
我想知道,这是由于图形的大量使用?我使用了太多的Grid布局吗?但是,我需要Grids以便我可以拥有分辨率独立性.
该应用程序在我的开发机器上运行良好,但在具有较低性能的机器上运行速度非常慢.是的,这是可以预料的,但不是我所看到的程度.我的雇主坚持认为应用程序在这些性能较低的机器上运行顺畅.
我已经对应用程序进行了一些分析,看起来需要花费最多时间的是显示内容(尽管我不确定我是否完全理解如何有效地使用分析器).
如果WPF导致速度减慢,我该怎么做才能改善这一点?
如何仅选择查询的前10个结果?
我想只显示以下查询的前10个结果:
SELECT a.names,
COUNT(b.post_title) AS num
FROM wp_celebnames a
JOIN wp_posts b ON INSTR(b.post_title, a.names) > 0
WHERE b.post_date > DATE_SUB(CURDATE(), INTERVAL 1 DAY)
GROUP BY a.names
ORDER BY num DESC
Run Code Online (Sandbox Code Playgroud) 我在sh(Mac OSX 10.6)中有这个小脚本来查看一系列文件.谷歌此时已停止提供帮助:
files="*.jpg"
for f in $files
do
echo $f | grep -oEi '[0-9]+_([a-z]+)_[0-9a-z]*'
name=$?
echo $name
done
Run Code Online (Sandbox Code Playgroud)
到目前为止(显然,对于你的shell大师)$name只有0,1或2,具体取决于是否grep发现文件名与提供的内容匹配.我想要的是捕获parens中的内容([a-z]+)并将其存储到变量中.
如果可能的话,我只想使用它grep.如果没有,请不要使用Python或Perl等,sed或类似的东西 - 我是shell的新手,并希望从*nix纯粹的角度来攻击它.
另外,作为一个超酷的bonu,我很好奇如何在shell中连接字符串?我捕获的组是$ name中存储的字符串"somename",我想在其末尾添加字符串".jpg",是cat $name '.jpg'吗?
如果你有时间,请解释一下发生了什么.
在Android 1.6中,点击微调器(下拉菜单)后,微调器选项旁边会出现单选按钮.如何删除这些单选按钮,以便只保留选项文本?
在 Firefox 中,每当我请求返回内容类型为“application/json”的页面时,Firefox 都会将该文件保存到 /tmp 中,但随后会说“/tmp/json.php 无法打开,因为关联的帮助应用程序没有存在。在您的首选项中更改关联。” 好吧,我进入“编辑”>“首选项”>“应用程序”,那里没有列出似乎与 application/json 有任何关系的内容类型。
是否可以为此类型添加条目?(或者对于我编写的随机自定义类型,例如“foo/bar”?)我看到一个名为 mimeTypes.rdf 的文件,它看起来很有希望。
如何"突出显示"(转向不同的颜色,制作粗体,等等......)已被点击的链接?
示例如下:http://www.celebrything.com/ 尝试获取右侧边栏中的今日,周和月链接,以便在单击后变为不同的颜色.
这是我用于在右侧边栏中显示结果的代码:
<div id="sidebar">
<div class="post">
<h2>
<font color="#333333">Top 50 Celebrities</font>
<br>
<br>
<font color="#333333"><a href="index.php?table=today">Today</a></font>
<font color="#333333"><a href="index.php?table=week">Week</a></font>
<font color="#333333"><a href="index.php?table=month">Month</a></font>
</font>
<br>
<br>
<?php
function showTable ($table){
if (!in_array($table, array('today', 'week', 'month'))) {
return false;
}
global $wpdb;
$result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_' . $table);
foreach($result as $row) {
echo '<a href="http://www.celebrything.com/?s=' .
urlencode($row->name) . '&search=Search">' . $row->name .
'</a> - ' . $row->count . ' Posts<br/>';
}
}
if (!empty($_GET['table'])) …Run Code Online (Sandbox Code Playgroud) 这可能是我看不到的简单因为我已经盯着它看太久了.
有任何想法吗?它在119线投掷,我在下面说明了
解析错误:语法错误,第119行/home6/cleanai4/public_html/act.php中的意外T_STRING
我只是想格式化一个电话号码.
if(isset($submit)):
$db = mysql_connect("localhost", "#######", "#######");
mysql_select_db("###########", $db);
$date = date("Y-m-d");
$address = $street . ", " . $city . " " . $zip;
Line 19-> $phonetmp = '('substr($phone, 0, 3)')' . substr($phone, 3, 3) . '-' . substr($phone, 6);
$phone = $tmp;
$sql = "INSERT INTO ########
VALUES(NULL,'$name', '$address', '$email', '$phone', '$info', '$sign', '$date' )";
mysql_query($sql);
print("<h2>We appreciate your support</h2>\n");
print("<b>Now, spread the word</b><hr>\n");
endif;
Run Code Online (Sandbox Code Playgroud) 我需要将此图像拉伸到可能的最大尺寸,而不会溢出<div>或倾斜图像.
我无法预测图像的宽高比,因此无法知道是否使用:
<img src="url" style="width: 100%;">Run Code Online (Sandbox Code Playgroud)
要么
<img src="url" style="height: 100%;">Run Code Online (Sandbox Code Playgroud)
我不能同时使用两者(即style ="width:100%; height:100%;")因为这将拉伸图像以适应<div>.
该<div>具有的大小为屏幕,这也是不可预测的百分比来设置.
c# ×2
php ×2
android ×1
bash ×1
content-type ×1
css ×1
firefox ×1
grep ×1
highlighting ×1
html ×1
hyperlink ×1
image ×1
java ×1
json ×1
mysql ×1
ninject ×1
performance ×1
server.xml ×1
shell ×1
size ×1
spinner ×1
sql ×1
tomcat6 ×1
ubuntu-9.10 ×1
wpf ×1