我试图在Unity 2.0的配置文件中注册一个泛型类型,但似乎无法正确.我在这里指的是MS文档:http://msdn.microsoft.com/en-us/library/ff660933%28v=PandP.20%29.aspx#_Generic_Types
代码如下所示:
public interface IRepository<T> where T : class
{
...
}
public class GenericRepository<T> : IRepository<T> where T : class
{
...
}
public class BlogRepository : GenericRepository<BlogRepository>
{
...
}
Run Code Online (Sandbox Code Playgroud)
我目前的XML配置是这样的:
<unity>
<!-- Aliases -->
<alias alias="BlogIRepository"
type="X.Services.Interfaces.IRepository[[X.Domain.Entities.Blog, X.Domain]], X.Services"/>
<alias alias="BlogRepository"
type="X.Repositories.BlogRepository, X.Repositories"/>
<!-- Type registration -->
<container name="development">
<!-- Common connection string value -->
<instance name="Conn" type="System.String" value="blahblahblah"/>
<register type="BlogIRepository" mapTo="BlogRepository">
<constructor>
<param name="connectionString" type="System.String" dependencyName="Conn"/>
</constructor>
</register>
</container>
</unity>
Run Code Online (Sandbox Code Playgroud)
根据注册泛型类型的文档,你周围使用泛型类型方括号,如果类型不是系统类型你提供完全限定的类型里面更多的方括号.我想,这就是我所做的.然而 - …
.net generics configuration inversion-of-control unity-container
我希望能够将属性应用于接口,以便实现该接口的任何类中的每个方法都将应用该属性.
我以为它看起来像这样:
[Serializable]
[AttributeUsage(AttributeTargets.All, Inherited = true)]
public sealed class TestAttribute : OnMethodBoundaryAspect
{
...
}
Run Code Online (Sandbox Code Playgroud)
然而,当我将它应用于如下界面时,在实现接口的类中调用方法时,永远不会访问属性中的OnEntry/OnExit代码:
[Test]
public interface ISystemService
{
List<AssemblyInfo> GetAssemblyInfo();
}
Run Code Online (Sandbox Code Playgroud)
如果我在实现类本身中应用该属性,如下所示,它可以正常工作:
[Test]
public class SystemService : ISystemService
{
...
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么/做错了什么?
我知道这里讨论的方法:
解决Linq to Sql中针对高需求ASP.NET网站的编译查询的常见问题
...但这对我的情况不起作用,因为我得到了:
"从查询返回结果后,不允许设置加载选项."
我使用Codesmith PLINQO脚本生成实体和管理器代码,管理器代码如下所示:
public partial class SearchManager
{
#region Query
// A private class for lazy loading static compiled queries.
private static partial class Query
{
internal static readonly Func<MyDataContext,IOrderedQueryable<Search>>
GetAll = CompiledQuery.Compile(
(MyDataContext db) =>
from s in db.Search
orderby s.Name
select s);
}
#endregion
public IQueryable<Search> GetAll()
{
return Query.GetAll(Context);
}
}
Run Code Online (Sandbox Code Playgroud)
我首先尝试将静态DataLoadOptions拖放到Searchmanager类中,如下所示:
public static readonly DataLoadOptions MyOptions =
(new Func<DataLoadOptions>(() =>
{
var option = new DataLoadOptions();
option.LoadWith<Search>(x => x.Rule);
return option; …Run Code Online (Sandbox Code Playgroud) 根据这些家伙的工作:
我正在尝试实现一个可以这样使用的TreeView助手:
<%= Html.TreeView("records",
Library.Instance.Records,
r => r.Children,
r => r.ID) %>
Run Code Online (Sandbox Code Playgroud)
树结构的定义如下:
public class Tree<T> : TreeNode<T> where T : TreeNode<T>
{ }
public class TreeNode<T> : IDisposable where T : TreeNode<T>
{
public T Parent { get; set; }
public TreeNodeList<T> Children { get; set; }
}
public class TreeNodeList<T> : List<TreeNode<T>> where T : TreeNode<T>
{
public T Parent;
public T Add(T node)
{
base.Add(node);
node.Parent = (T)Parent;
return node;
}
public void Remove(T node) …Run Code Online (Sandbox Code Playgroud) c# ×3
.net ×1
attributes ×1
collections ×1
generics ×1
ienumerable ×1
interface ×1
linq ×1
loadoptions ×1
postsharp ×1
tree ×1
treenode ×1