hmemcpy / AgentMulder

** THIS PLUGIN IS NO LONGER MAINTAINED. PLEASE FOLLOW ERNICOMMUNITY FOR UPDATES **
https://github.com/ERNICommunity/AgentMulder
MIT License
151 stars 33 forks source link

Autofac Support #6

Closed JakeGinnivan closed 10 years ago

JakeGinnivan commented 12 years ago

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

hmemcpy commented 12 years ago

Working on it now :)

hmemcpy commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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

hmemcpy commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago
var makeGenericMethod = createProxyMethod.MakeGenericMethod(service);
>>>> ContainerBuilder.Register(cc =>

That line in particular is the one it jumps to

hmemcpy commented 12 years ago

Thanks for your report!

Types registered by reflection are a bit problematic to detect, so they are currently not really supported. I'll take a look at the "false positive" produced by Mulder, though...

Thanks again!

Sent from my Windows Phone From: Jake Ginnivan Sent: 05-Jul-12 4:48 To: Igal Tabachnik Subject: Re: [AgentMulder] Autofac Support (#6) 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(); return makeGenericMethod.Invoke(wcfServiceClientFactory, null); }).As(serviceContract); }

        return serviceContracts.ToDictionary(k => k.Name);
    }

Reply to this email directly or view it on GitHub: https://github.com/hmemcpy/AgentMulder/issues/6#issuecomment-6770264

JakeGinnivan commented 12 years ago

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 commented 11 years ago

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 commented 11 years ago

@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 commented 11 years ago

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 commented 11 years ago

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 commented 11 years ago

Awesome, thanks! Love the plugin!