我之前提出过这个问题,但我仍然在努力寻找一个可以让我理解的例子(请不要只是告诉我看看S#arp架构项目,至少没有一些方向).
到目前为止,我已经在我的网络项目中实现了近乎持久的无知.我的存储库类(在我的数据项目中)在构造函数中使用了一个ISession:
public class ProductRepository : IProductRepository
{
private ISession _session;
public ProductRepository(ISession session) {
_session = session;
}
Run Code Online (Sandbox Code Playgroud)
在我的global.asax中,我公开当前会话,并在beginrequest和endrequest上创建和处理会话(这是我对NHibernate的依赖):
public static ISessionFactory SessionFactory = CreateSessionFactory();
private static ISessionFactory CreateSessionFactory() {
return new Configuration()
.Configure()
.BuildSessionFactory();
}
protected MvcApplication() {
BeginRequest += delegate {
CurrentSessionContext.Bind(SessionFactory.OpenSession());
};
EndRequest += delegate {
CurrentSessionContext.Unbind(SessionFactory).Dispose();
};
}
Run Code Online (Sandbox Code Playgroud)
最后我的StructureMap注册表:
public AppRegistry() {
For<ISession>().TheDefault
.Is.ConstructedBy(x => MvcApplication.SessionFactory.GetCurrentSession());
For<IProductRepository>().Use<ProductRepository>();
}
Run Code Online (Sandbox Code Playgroud)
看来我需要我自己的ISession和ISessionFactory的通用实现,我可以在我的web项目中使用它并注入我的存储库?
所以只是为了澄清 - 我在我的存储库层使用NHibernate并希望使用session-per-(http)请求.因此,我正在向我的存储库构造函数中注入一个ISession(使用structuremap).目前,为了在每个请求中创建和处理会话,我必须从我的web项目中引用NHibernate.这是我想要删除的依赖项.
谢谢,本
下面是我用来返回分页对象列表的代码:
string query2 = @"
select count(*) as TotalCount from blogposts p where p.Deleted = 0 and p.PublishDate <= @date
select * from (
select p.*,
row_number() over(order by publishdate desc) as rownum
from blogposts as p
where p.Deleted = 0 and p.PublishDate <= @date
) seq
where seq.rownum between @x and @y";
using (var cn = new SqlConnection(connectionString))
{
cn.Open();
using (var multi = cn.QueryMultiple(query2, new { x= lower, y = upper, date = DateTime.UtcNow }))
{
var totalCount …Run Code Online (Sandbox Code Playgroud) 鉴于下面的测试用例我怎么能:
IList<TestObject>基于匹配的索引Id
中的IList<int>列表.list[3] == 3和list[4] == 4.IList(我不能使用List<T>)这是测试:
public class TestObject
{
public int Id { get; set; }
}
[Test]
public void Can_reorder_using_index_list()
{
IList<TestObject> list = new List<TestObject>
{
new TestObject { Id = 1 },
new TestObject { Id = 2 },
new TestObject { Id = 3 },
new TestObject { Id = 4 },
new TestObject { …Run Code Online (Sandbox Code Playgroud) 我正在使用反射创建泛型类型的实例:
public interface IModelBuilder<TModel>
{
TModel BuildModel();
}
public class MyModel
{
public string Name { get; set; }
}
public class MyModelBuilder : IModelBuilder<MyModel>
{
public MyModel BuildModel()
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
在运行时,我们所知道的是模型的类型,例如MyModel.我可以找到相关模型构建器的实例,如下所示:
var modelBuilders = from t in Assembly.GetExecutingAssembly().GetTypes()
from i in t.GetInterfaces()
where i.IsGenericType
&& i.GetGenericTypeDefinition() == typeof(IModelBuilder<>)
&& i.GetGenericArguments()[0] == modelType
select t;
var builder = Activator.CreateInstance(modelBuilders.First());
Run Code Online (Sandbox Code Playgroud)
但我不知道如何然后IModelBuilder<TModel>我可以调用实例,因此我可以调用并使用结果BuildModel().
我们有一个文件系统抽象,允许我们在本地和云(Azure)存储之间轻松切换.
对于读写文件,我们有以下成员:
Stream OpenRead();
Stream OpenWrite();
Run Code Online (Sandbox Code Playgroud)
我们的部分应用程序将文件"捆绑"到一个文件中.对于我们的本地存储提供程序,OpenWrite返回可附加的流:
public Stream OpenWrite()
{
return new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, BufferSize, useAsync: true);
}
Run Code Online (Sandbox Code Playgroud)
对于Azure blob存储,我们执行以下操作:
public Stream OpenWrite()
{
return blob.OpenWrite();
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这每次都会覆盖blob内容.是否可以返回可附加到的可写流?
我正在关注Chris Pietschmann 在ASP.NET MVC中使用主题的解决方案.
我注意到的一件事是在后续请求中没有从ViewLocationCache中检索视图名称.我正在使用ASP.NET MVC 2.0 RC
执行以下代码时:
this.ViewLocationCache.InsertViewLocation(controllerContext.HttpContext, cacheKey, virtualPath);
Run Code Online (Sandbox Code Playgroud)
我将鼠标悬停在this.ViewLocationCache上它只返回{System.Web.Mvc.NullViewLocationCache} - 建议什么都没有添加?
我们有一个应用程序分为两部分:
我正在寻找创建REST API来提供此功能.很容易看出如何表示CRUD操作,但我不确定单个资源上的特定操作(命令).例如,为了"发布",Project我们发送一个"PublishCommand".我们不会将Project其Published属性设置为的完全返回到服务器true.
在类似的说明中,我对如何在不被归类为RPC类型服务的情况下代表更高级的资源查询操作感到困惑.
下面我列出了我的Project资源的URI模板.我是否正在创建真正的RESTful API?
ADMIN API
---------
// Project Resources
GET /projects -- get all projects
POST /projects -- create a new project
// Project Resource
GET /projects/10 -- get project with id 10
PUT /projects/10 -- update project with id 10
DELETE /projects/10 -- delete project with id 10
// Project Resource Operations
POST: /projects/10/publish -- publish project with id 10 …Run Code Online (Sandbox Code Playgroud) HTML:
<ul>
<li></li>
<li></li>
<li class="img"></li>
<li></li>
<li class="img"></li>
<li class="img"></li>
<li></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
CSS:
ul {
list-style-type: none;
}
li {
background-color: red;
margin: 5px;
width: 30px;
height: 30px;
float: left;
}
li.img:not(:first-child) {
background-color: blue;
}
Run Code Online (Sandbox Code Playgroud)
结果:
http://jsfiddle.net/benfosterdev/K3ZnA/
我希望除了第一个之外的所有人li.img都有蓝色背景.
我正在使用jQuery执行AJAX POST,如下所示:
self.post = function (path, data) {
return $.ajax({
url: this.createUri(path),
type: "POST",
contentType: "application/json",
dataType: "json",
data: ko.toJSON(data)
});
};
Run Code Online (Sandbox Code Playgroud)
这里我只返回AJAX Deferred对象.响应由另一个对象处理:
api.post(menuItemsUri, self.newItem)
.done(function (data, textStatus, request) {
console.log(request.getResponseHeader("Location")); // undefined
})
.always(function () {
// reset the current item
self.newItem.update({});
});
Run Code Online (Sandbox Code Playgroud)
服务器返回201 Created响应并设置Location标头.我可以在Chrome网络标签中看到这一点:
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Content-Length:0
Date:Thu, 07 Feb 2013 10:25:04 GMT
Expires:-1
Location:http://localhost:49978/sites/1/menus/65/items/19
Pragma:no-cache
Run Code Online (Sandbox Code Playgroud)
但是,XmlHttpRequest在jQuery AJAX回调中传递的对象中缺少Location标头.
我从Illustrator导出了一个SVG,想要设置SVG的高度并按比例增加宽度比例.
这是SVG的示例:
<svg xmlns="http://www.w3.org/2000/svg" width="20px" height="10px" viewBox="0 0 20 10">
<path fill="#124C92" d="M20,7c0,1.65-1.35,3-3,3H3c-1.65,0-3-1.35-3-3V3c0-1.65,1.35-3,3-3h14c1.65,0,3,1.35,3,3V7z" />
</svg>
Run Code Online (Sandbox Code Playgroud)
如果我只设置高度,则SVG宽度设置为100%.
到目前为止,我一直无法找到一个不需要我设置高度和宽度的解决方案.
asp.net-mvc ×2
c# ×2
.net ×1
ajax ×1
asp.net ×1
azure ×1
collections ×1
css ×1
css3 ×1
dapper ×1
jquery ×1
nhibernate ×1
reflection ×1
rest ×1
structuremap ×1
svg ×1
viewengine ×1