<commit_before>=============================
Passing Parameters to Resolve
=============================

Notes for doc writing:

- Correpsonds to wiki page: https://github.com/autofac/Autofac/wiki/Resolve-Parameters
- Cross-link to the pages on registering with parameters, delegate factories, and implicit relationships.<commit_msg>Filled out doco for Passing Parameters to Resolve.<commit_after>=============================
Passing Parameters to Resolve
=============================

``Resolve`` accepts :doc:`parameters<../register/parameters>` using a variable-length argument list:

.. sourcecode:: csharp

    var fred = Resolve<Person>(new NamedParameter("name", "Fred"));

This will map automatically to the named constructor parameters on the implementation class, if it was registered using Reflection, e.g.:

.. sourcecode:: csharp

    class Person
    {
      public Person(string name)
      ...

Available Parameter Types
-------------------------

Autofac offers several different parameter matching strategies:

 * ``NamedParameter`` - match target parameters by name as above
 * ``TypedParameter`` - match target parameters by type (exact type match required)
 * ``ResolvedParameter`` - flexible parameter matching

``NamedParameter`` and ``TypedParameter`` can supply constant values only.

``ResolvedParameter`` can be used as a way to supply values dynamically retrieved from the container, e.g. by resolving a service by name.

Utilising Parameters from an Expression
---------------------------------------

If ``Person`` is to be registered using an expression, the parameters can be accessed from a second available delegate parameter of type ``IEnumerable<Parameter>``:

.. sourcecode:: csharp

    builder.Register((c, p) => new Person(p.Named<string>("name")));

Delegate Factories
------------------

Check out :doc:`the delegate factory feature<../advanced/delegate-factories>` and the ``Func<T>`` :doc:`relationship type<../resolve/relationships>` for a cleaner way to create components that require parameters.
{'fraction_non_alphanumeric': 0.18092909535452323, 'fraction_numerical': 0.0, 'mean_word_length': 4.12781954887218, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3072519', 'n_tokens_mistral': 488, 'n_tokens_neox': 465, 'n_words': 199}