zcz527 / autofac

Automatically exported from code.google.com/p/autofac
Other
0 stars 0 forks source link

AsImplementedInterfaces(), AsSelf() don't work with non-generic version of RegisterType() #293

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
AsImplementedInterfaces and AsSelf registration options do not work when type 
of service being registered is specified with serviceType parameter. In this 
case TLimit type parameter is Object and these methods obtain info from type 
TLimit rather than type serviceType.

See the following example:

        public interface IService { }
        public class Service1 : IService { }

        [Test]
        public void AsImplementedInterfaces()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType(typeof(Service1)).AsImplementedInterfaces();
            var context = builder.Build();

            context.Resolve<IService>(); // fails
        }

        [Test]
        public void AsSelf()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType(typeof(Service1)).AsSelf();
            var context = builder.Build();

            context.Resolve<Service1>(); // fails
        }

What version of Autofac are you using? 2.4

Original issue reported on code.google.com by mrdont@mail.ru on 9 Feb 2011 at 5:59

GoogleCodeExporter commented 8 years ago
Btw, I've just found the same issue in google groups 
(https://groups.google.com/forum/#!topic/autofac/ENN0PFF_UpQ) and there was 
stated that this limitation is fixed in the "upcoming 2.4 series". Or it isn't?

Original comment by mrdont@mail.ru on 9 Feb 2011 at 7:25

GoogleCodeExporter commented 8 years ago
Thanks - I think the original issue was just supporting any non-scanning 
registrations; I'll take a look at the non-generic RegisterType() and see 
what's going wrong.

Cheers,
Nick

Original comment by nicholas...@gmail.com on 12 Feb 2011 at 11:49

GoogleCodeExporter commented 8 years ago
Nuts - just got bitten by this one as well. It works happily with 
.RegisterAssemblyTypes() but not with a single type parameter.

Original comment by andr...@uglybugger.org on 7 Mar 2011 at 7:32

GoogleCodeExporter commented 8 years ago
Thanks for following up. I originally misread this and didn't realise what a 
serious bug it is. The other similar reported issue was about missing 
overloads, not failing ones.

I'll get a fix out for this in a couple of days.

Cheers,
Nick

Original comment by nicholas...@gmail.com on 7 Mar 2011 at 10:34

GoogleCodeExporter commented 8 years ago
Fixed, thanks.

Original comment by nicholas...@gmail.com on 9 Mar 2011 at 9:10

GoogleCodeExporter commented 8 years ago
Thou art a legend. Thank you :)

Original comment by andr...@uglybugger.org on 16 Mar 2011 at 10:33