views:

113

answers:

1

How can I manage the lifetime of my services in mvc turbine (using Unity)?

I have an ISearchService implementation LuceneSearchService that takes an IConfigurationService and ILoggerService.

Currently my searchservice registration looks like this:

public class SearchServiceRegistration: IServiceRegistration
{
    public void Register(IServiceLocator locator)
    {
        locator.Register<ISearchService, LuceneSearchService>();
    }
}

I would like to keep the responsibility of creating the instance in Turbine, but I want it to be a singleton.

Or in other words, how can I define the lifetime?

+1  A: 

Currently the Turbine bits don't allow for lifetime management since I felt that was best suited work for your container. If you're interested, you can use something like what I define on this blog post: Injecting Your Favorite IoC Into MVC Turbine

If you're OK with exposing your container with your within your IServiceRegistration implementation you can do something like this: HACK to expose your specific SL within your registration

If I get a lot of requests for the need of lifetime management, I will add it to V3 of Turbine.

Javier Lozano
Thanks. In the mean time I had found out that I could create my container myself. But because my services need other services that are not autodiscovered when I create my container I now have to do the entire registration myself. Which is a bummer. Anticipating V3 :D Also: I want to thank you for Turbine. I finally got the hang of a concept I was trying to grasp for months now :)
borisCallens
I guess, not following your statement, "my services need other services that are not autodiscovered when I create my container I now have to do the entire registration myself."What are you trying to do? Typically with the IServiceLocator that is exposed, you register services that are transient and require simple registration within your application. Providing your own container is meant for more complex registrations.If you don't mind me asking, which container are you using?
Javier Lozano