I am just starting to work with IoC frameworks and am playing with Autofac.
In the following code example, where I register 2 completely different classes (in global.asax) that implement the same interface, I wonder how we guarantee that the correct Autofac is used? Currently, one of my controllers that accepts IPhotoBlogRepository as their constructor is either passing PhotoBlogRepositoryOR a TestRepository, depending on which appears first / last in the code below.
PhotoBlogRepository
TestRepository
builder.RegisterType<PhotoBlogRepository>().As<IPhotoBlogRepository>(); builder.RegisterType<TestRepository>().As<IPhotoBlogRepository>();
. , . , , .
, IEnumerable<IPhotoBlogRepository>. Autofac , .
IEnumerable<IPhotoBlogRepository>
, , Autofac .
: , . SUT ( ) , . "" , .
, , , , , , , PreserveExistingDefaults() , :
PreserveExistingDefaults()
builder.RegisterType<PhotoBlogRepository>().As<IPhotoBlogRepository>(); builder.RegisterType<TestRepository>().As<IPhotoBlogRepository>().PreserveExistingDefaults();
- , PreserveExistingDefaults().
Source: https://habr.com/ru/post/1778794/More articles:SQL conditional column existence - sqlchecking if fork () is safe - multithreadingexplicit creation of a function template fails (g ++) - c ++Manipulating a text data file with the bash command? - bashFirefox and html5 video - gray box with x - debuggingSequence Points in C ++ and Exceptions - c ++Designing a web game that will work in a browser - where do I start? - pythonhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1778797/datetime-has-too-many-decimal-places&usg=ALkJrhhveSko5vKAj3n5wFuCaWavkf9i-wHaskell ~ Завершает ли последний весь список? - listHow to deserialize in PHP an object serialized in Java - javaAll Articles