English 中文(简体)
使用输入来手动满足对现有对象的依赖性
原标题:Use Ninject to manually satisfy dependencies on existing object

我成功地在一个项目中使用了Ninject, 在那里我可以有像这样的课:

public class MyServiceConsumer
{
    [Inject]
    public void IPropertyInjectedService { get; set; }

    private IConstructorInjectedService _conSvc;

    public MyServiceConsumer(IConstructorInjectedService conSvc)
    {
        _conSvc = conSvc;
    }
}

如果我做了内核。 Get & lt; My ServiceConsumer> (), 依赖性将会得到满足, 一切都会好起来。 但是在应用程序启动时, 有一种假设, 我已经有了一个已有对象, 我想把它传给内核, 让内核对当前实例进行财产注入 。

我如何将现有物体传递给注射器内核, 使财产的注射依赖性得到满足?

问题回答

我要找的语法是:

kernel.Inject(myExistingInstanceWithDependencies);




相关问题
How to Inject Open Connections with an IoC

First, my scenario. I have a service, BillingService, has a constructor like this: BillingService(IInstallmentService, IBillingRepository) The InstallmentService has a constructor that looks like ...

Using the Ninject kernel as a Unit of Work object factory

So I m starting to use Ninject for dependency injection and I m wondering what people think of using a kernel as an object factory for Unit of Work type objects like Linq2Sql Datacontexts. I would ...

array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Unity constructors

I have setup unity in my project and it is working for objects that don t have constructor injection implemented on them. The issue is now I do have an object which requires a custom object as a ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

ASP.NET MVP Injecting Service Dependency

I have an ASP.NET page that implements my view and creates the presenter in the page constuctor. Phil Haack s post providing was used as the starting point, and I ll just the examples from the post ...

Authorization and Windsor

I m trying to implement my custom authorize attribute like: public class MyCustomAuth : AuthorizeAttribute { private readonly IUserService _userService; public MyCustomAuth(IUserService ...

热门标签