Skip to content

Commit

Permalink
Changed the examples of AppendToCollection to the new Collections.App…
Browse files Browse the repository at this point in the history
…endTo syntax. Feature: simpleinjector/SimpleInjector#517
  • Loading branch information
dotnetjunkie committed Mar 23, 2018
1 parent 1bf43b7 commit 560c6c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
6 changes: 2 additions & 4 deletions source/advanced.rst
Expand Up @@ -293,11 +293,9 @@ In most cases however, manually supplying the **RegisterCollection** with a list

.. code-block:: c#
// Extension method from the SimpleInjector.Advanced namespace.
container.AppendToCollection(typeof(IValidator<>), typeof(DataAnnotationsValidator<>));
container.Collections.AppendTo(typeof(IValidator<>), typeof(DataAnnotationsValidator<>));
container.RegisterCollection(typeof(IValidator<>),
new[] { typeof(IValidator<>).Assembly });
container.RegisterCollection(typeof(IValidator<>), typeof(IValidator<>).Assembly);
.. container:: Note

Expand Down
10 changes: 3 additions & 7 deletions source/using.rst
Expand Up @@ -437,20 +437,16 @@ The previous code snippet will register all *ILogger* implementations that can b
Adding registrations to an existing collection
----------------------------------------------

In most cases you would register a collection with a single line of code. There are cases where you need to append registrations to an already registered collection. Common use cases for this are integration scenarios where you need to interact with some framework that made its own registrations on your behalf, or in cases where you want to add extra types based on configuration settings. In these cases it might be benifecial to append registrations to an existing collection.
In most cases you would register a collection with a single line of code. There are cases where you need to append registrations to an already registered collection. Common use cases for this are integration scenarios where you need to interact with some DI Containers that made its own registrations on your behalf, or in cases where you want to add extra types based on configuration settings. In these cases it might be benifecial to append registrations to an existing collection.

To be able to do this, Simple Injector contains the **AppendToCollection** extension method in the **SimpleInjector.Advanced** namespace.

.. container:: Note

**Note**: This extension method will not show up using IntelliSense, unless you include the **SimpleInjector.Advanced** namespace to your code file. This extension method is deliberately hidden to prevent polluting the main API; appending to existing collections is not a common use case.
To be able to do this, Simple Injector contains the **Collections.AppendTo** method.

.. code-block:: c#
Assembly[] assemblies = // determine list of assemblies to search in
container.RegisterCollection(typeof(ILogger), assemblies);
container.AppendToCollection(typeof(ILogger), typeof(ExtraLogger));
container.Collections.AppendTo(typeof(ILogger), typeof(ExtraLogger));
.. _Verifying-Container:
Expand Down

0 comments on commit 560c6c4

Please sign in to comment.