相关疑难解决方法(0)

如何使用Ninject处理带静态方法的类?

如何使用Ninject处理带静态方法的类?

也就是说,在C#中,一个接口中不能有静态方法,而Ninject在使用接口的基础上工作?

我的用例是一个类,我希望它有一个静态方法来创建一个未填充的自身实例.

编辑1

只是在TopologyImp类中添加一个示例,在GetRootNodes()方法中,如何创建一些要返回的iNode类?我会用正常的代码练习构建这些或者我会以某种方式使用Ninject吗?但是,如果我使用容器创建那么我没有给IOC这个库知识呢?

public interface ITopology
{
    List<INode> GetRootNodes();
}


public class TopologyImp : ITopology
{
    public List<INode> GetRootNodes()
    {
        List<INode> result = new List<INode>();

        // Need code here to create some instances, but how to without knowledge of the container?
        // e.g. want to create a few INode instances and add them to the list and then return the list 
    }
}

public interface INode
{
    // Parameters
    long Id { get; set; }
    string Name { …
Run Code Online (Sandbox Code Playgroud)

dependency-injection ninject

14
推荐指数
1
解决办法
7830
查看次数

标签 统计

dependency-injection ×1

ninject ×1