views:

158

answers:

1
    container.Register(
        AllTypes.Pick().FromAssembly(typeof (UserRepository).Assembly)
            .WithService.FirstInterface());

Currently the code above will work fine if the interface are also in the same assembly but it will blow up if IUserRepository is from a different assembly.

Is auto registration from two different assemblies possible? Am I missing something here?

+2  A: 

Yes, it's possible to define auto-registration where the interface is defined in a different assembly. We do it, although we use a slightly different syntax:

container.Register(AllTypes
    .FromAssemblyContaining<ConfigurationService>()
    .Where(t => t.Name.EndsWith("Service", StringComparison.Ordinal))
    .WithService
    .FirstInterface()
    .Configure(reg => reg.LifeStyle.PerWebRequest));

I can't say if the different API usage makes a difference, but I would assume that it doesn't. Rather, I would guess that the cause of the error you experience is that perhaps the assembly containing the interface isn't available.

Check if Fusion can load the type from that application at all.

Mark Seemann
You are right it's possible. My problem was that UserRepository inherit from a base class that inherit from another interface. So the interface from the base class got pick up instead.Though thanks to you I don't have to end up chasing a ghost tail.I've also edit the question to include the solution
firefly

related questions