Autofac Support #6

Closed
JakeGinnivan opened this Issue May 22, 2012 · 14 comments

4 participants

@JakeGinnivan

Awesome idea! I would love to see autofac support, if I get the time/motivation I might send a few PR's :)

@hmemcpy hmemcpy was assigned May 22, 2012
@hmemcpy
Owner

Working on it now :)

@hmemcpy
Owner

Finally added in v1.0.4! Please download it and let me know if you have any issues :)
https://github.com/downloads/hmemcpy/AgentMulder/AgentMulder1.0.4.msi

If it works, please feel free to close this issue!

@JakeGinnivan

Hey, sorry I haven't tested this, I am actually running vs2012 and r#7 :( So will follow issue #12 and test once a supporting release comes out.

Looking forward to it!

@DanielTheCoder

Current version (1.0.4.2) is working fine with VS2012 RC, R#7 Build 80 and Autofac

@hmemcpy
Owner

Glad to see that it is working!

If you're comfortable with the support for now (no outstanding bugs with Autofac), please feel free to close the issue.

@JakeGinnivan

Just had a quick look, looks nice. I do have a small issue though :)

We use reflection to register many of our services, and the Registered with autofac jump to button always jumps to this block of code, rather than the actual registration.

    private Dictionary<string, Type> RegisterServiceContracts()
    {
        var serviceContracts =
            typeof(Store.Contracts.StoreConfigurationManagement.Interfaces.IConfigurationService)
            .Assembly
            .GetTypes()
            .Where(t => t.IsInterface && t.GetCustomAttributes(typeof(System.ServiceModel.ServiceContractAttribute), true).Any())
            .Union(
            typeof(Central.Contracts.CentralContractsDataContractSerializerKnownTypeProvider)
            .Assembly
            .GetTypes()
            .Where(t => t.IsInterface && t.GetCustomAttributes(typeof(System.ServiceModel.ServiceContractAttribute), true).Any())
            ).ToList();

        var createProxyMethod = typeof(WcfServiceClientFactory).GetMethod("CreateProxy");
        foreach (var serviceContract in serviceContracts)
        {
            Type service = serviceContract;
            var makeGenericMethod = createProxyMethod.MakeGenericMethod(service);
            ContainerBuilder.Register(cc =>
            {
                var wcfServiceClientFactory = cc.Resolve<WcfServiceClientFactory>();
                return makeGenericMethod.Invoke(wcfServiceClientFactory, null);
            }).As(serviceContract);
        }

        return serviceContracts.ToDictionary(k => k.Name);
    }
@JakeGinnivan
var makeGenericMethod = createProxyMethod.MakeGenericMethod(service);
>>>> ContainerBuilder.Register(cc =>

That line in particular is the one it jumps to

@hmemcpy
Owner
@JakeGinnivan

I'm fine with reflection registered types not being registered, we have a VERY complex app which relies very heavily on IoC.

Fixing the false positive would be awesome though, as that makes Mulder not so useful.

I will try to report as much as I can because I can probably find some edge cases :P

@eamodio

I am using the latest Mulder with Autofac and while it seems great at detecting registrations, when you click on the "Registered by Autofac (click to navigate)" icon it navigates to the correct file, but doesn't seem to get the line number correct. I haven't had a change to fork the code and check it out myself, but I figured I'd raise the issue in case others are seeing the same behavior.

Thanks!
Eric

@hmemcpy
Owner

@eamodio Thanks for the report!

Would it be possible for you to paste here one such registration? Please keep the formatting and indentation exactly as you have it.

@eamodio

Sure - here are two:

        builder.RegisterAssemblyTypes(ThisAssembly)
            .AsClosedTypesOf(typeof(IApiService<>))
            .AsImplementedInterfaces()
            .PropertiesAutowired(PropertyWiringFlags.AllowCircularDependencies)
            .InstancePerLifetimeScope()
            .OnActivated(OnActivatedService);

        builder.RegisterAssemblyTypes(ThisAssembly)
            .AsClosedTypesOf(typeof(IElementService<>))
            .PropertiesAutowired(PropertyWiringFlags.AllowCircularDependencies)
            .InstancePerLifetimeScope()
            .OnActivated(OnActivatedService);

        builder.RegisterAssemblyTypes(ThisAssembly)
            .AsClosedTypesOf(typeof(IElementChildService<>))
            .PropertiesAutowired(PropertyWiringFlags.AllowCircularDependencies)
            .InstancePerLifetimeScope()
            .OnActivated(OnActivatedService);

The 2nd one works, but the 1st and 3rd always points to the line of the second one. And this happens for many other registrations - it gets the correct file, but wrong line number. FYI these registrations are inside an autofac module class. Let me know if I can provide any other details.

@hmemcpy
Owner

Thanks! I'll get on that as soon as possible! (Actually, as soon as I get some sleep, I just adopted a new pug puppy, he's a hyperactive little fellow :))

@eamodio

Awesome, thanks! Love the plugin!

@hmemcpy hmemcpy added a commit that referenced this issue Jan 25, 2013
@hmemcpy Added a check to Autofac, to prevent Mulder from registering types th…
…at are resolved as 'system.object'.

This solves (partially) issue #6, where types were registered incorrectly.
f869c9d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment