Question: I've got an interface, implementation, and target:

```
public interface IPerson { public string Name { get; } }
public class Person: IPerson { public string Name { get { return "John"; } } }
public class Target { public Target(IPerson person) {} }

```

I'm using Autofac to tie things together:

```
builder.RegisterType<Person>().As<IPerson>().SingleInstance();

```

The problem is that `IPerson` lives in a shared assembly, `Person` lives in a plugin (which may or may not be there), and `Target` lives in the main application that loads plugins. If there are no plugins loaded that implement `IPerson`, Autofac goes ballistic about not being able to resolve `Target`'s dependencies. And I cannot really blame it for that.

However I know that `Target` is able to handle the lack of an `IPerson` and would be more than happy to get a `null` instead. In fact, I'm pretty sure that all the components which rely on an `IPerson` are prepared to take a `null` it its stead. So how can I tell Autofac - "It's OK sweety, don't worry, just give me back a `null`, alright?"

One way I found is to add a default parameter to `Target`:

```
public class Target { public Target(IPerson person = null) {} }

```

That works, but then I need to do this for all the components that require an `IPerson`. Can I also do it the other way round? Somehow tell Autofac "If all else fails for resolving `IPerson`, return null"?

Answer: 
Just use optional parameters, see the following sample:

```
public class SomeClass
{
     public SomeClass(ISomeDependency someDependency = null)
     {
           // someDependency will be null in case you've not registered that before, and will be filled whenever you register that.
     }
}

```
As [Marc mentioned](https://stackoverflow.com/a/47401496/1811525), a [default implementation](https://docs.autofac.org/en/latest/best-practices/#use-constructor-injection) should be considered in the first place. But there are situations where this might not be appropriate for some reason. If `IService service = null` is not enough in some situation, [Adam Storr describes an alternative way](https://adamstorr.azurewebsites.net/blog/optional-dependencies-with-autofac) of annotating the constructor parameter as being optional (using a feature introduced with Autofac 5.x).

The result could look like this:

```
public class Target { public Target([Optional] IPerson person) {} }

```

The `OptionalAttribute` can dynamically decide what *default* value is returned.

Note that this attribute is required for every affected constructor (which is actually something the original poster would like to avoid).