What does AsSelf do in autofac?

What is AsSelf () in autophore? I'm new to autofac, what is AsSelf and what is the difference between the two below?

builder.RegisterType () AsSelf () As () ..; . Builder.RegisterType () Like ();

Thank!

+4
source share
1 answer

Usually you need to inject interfaces, not implementations into your classes.

But suppose you have:

interface IFooService { }

class FooService { }

Registration builder.RegisterType<FooService>()allows you to enter FooService, but you cannot embed IFooService, it even FooServiceimplements it. It is equivalent builder.RegisterType<FooService>().AsSelf().

builder.RegisterType<FooService>().As<IFooService>() IFooService, FooService - .As<T> "" " ", .

, , AsSelf() : builder.RegisterType<FooService>().As<IFooService>().AsSelf().

, builder.RegisterType<SomeType>().AsImplementedInterfaces() - , .

, Autofac ( ).

, Autofac

+12

Source: https://habr.com/ru/post/1666214/


All Articles