views:

90

answers:

1

Hi, I am using Dependency Injection to Inject interface into my few views. One of the requirement I need to Inject the interface into the custom control. I have tried using ServiceDependency attribute to inject interface , but it doesn't work.

public interface ISearchService
{
    void CustomizeLayout(ColumnCollection collection);
}
IService _service;

[ServiceDependency]
public IService Service
{
    get
    {
        return _service;
    }
    set
    {
        _service = value;
    }
}

then i m calling Service.CustomizeLayout(this.Columns) in my custom control. It throws Object ref not set to instance of an object (Service comes as a null).

Can somebody tell me wat could be the problem or how to inject dependency into a control similar way which we do for the win forms.

A: 

It's been a while since I've used CAB so forgive me if I got you wrong. Your problem is probably that the custom control ist not created by CAB and CAB is not aware of the control having dependencies when it creates the view containing the control. I remember having the problem, too but can't recall the exact solution :-(

longeasy
yeah this is the exact problem, i m trying to find it out, just one thing can we add controls as items collection of workitem.