views:

39

answers:

1

Hi,

I'm looking for an IoC container to use in my Compact Framework application. Trying out Funq I noticed that I can't find a way to do Property Injection with it.

I've looked through the discussion on the project's site and the unit tests for it, but I can't find any example of Property Injection.

Does Funq support Property Injection?

A: 

Well wouldn't that generally go something like this?

myContainer.Register<IUserRepository>(() =>
    {
        var myRepository = new SomeUserRepository();
        myRepository.SomeProperty = someValue;

        return myRepository;
    });
herzmeister der welten
`someValue` in this context is usually a service from the container. How do you get to that service?
Peter Lillevold
`myRepository.SomeProperty = myContainer.Resolve<TSomeService>();` ?
herzmeister der welten
Got an answer on Funq forum. In Funq you actually get the container in a parameter to the provider method, so you can do:myContainer.Register<IUserRepository>((c)=>new SomeUserRepository(){SomeProperty = c.Resolve<SomeService>()});
Michał Drozdowicz
The property initializer syntax is surely more concise. That the Funq framework provides the container as a lambda parameter again is a good idea and helps the compiler to avoid capturing which might have negative impact on the lifetime of the container, and helps beginners to avoid unwanted closure side effects.
herzmeister der welten