Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Update method on Autofac builder is obsolete #64

Open
dario-l opened this issue Dec 8, 2016 · 6 comments
Open

Update method on Autofac builder is obsolete #64

dario-l opened this issue Dec 8, 2016 · 6 comments

Comments

@dario-l
Copy link

dario-l commented Dec 8, 2016

Autofac documentation says:

While Autofac provides an Update() method to update registrations in an existing container, for the most part it’s there for backwards-compatibility with Autofac 2.x. Where at all possible, you should avoid updating a container and instead register everything up front before building the container.

http://docs.autofac.org/en/latest/best-practices/index.html#consider-a-container-as-immutable

And they make Update obsolete:

Containers should generally be considered immutable. Register all of your dependencies before building/resolving. If you need to change the contents of a container, you technically should rebuild the container. This method may be removed in a future major release.

This leads to major modifications in this bootstrapper.

@khellang
Copy link
Member

khellang commented Dec 8, 2016

Yes. The current design was based around the assumption that the containers could be modified after the initial registrations. This has also caused trouble with containers like SimpleInjector, which simply doesn't allow you to do this.

We've been prototyping a bootstrapper design which doesn't have these assumptions. It collects all registrations up-front and relies on scoping and/or nested containers/lifetimes to provide request-scoped dependencies. Hopefully we'll be able to get that rolled into Nancy at some point in the future.

@grumpydev
Copy link
Member

As I've said before though, that prototype doesn't cover all the use cases we cover. There's a key difference between something being immutable, and its API not allowing you to "change" it. Strings are immutable in .net, but that doesn't ,mean you can't do "mystring = mystring + otherstring", it just returns a new string instance - this is exactly how I'd expect containers to work that require internal immutability for performance.

@khellang
Copy link
Member

khellang commented Dec 8, 2016

@grumpydev Are you trying to say that we can't cover these use cases by having an immutable container?

@thecodejunkie
Copy link
Member

@khellang

Hopefully we'll be able to get that rolled into Nancy at some point in the future.

I'll commit to work with you on this asap if you're up for it :P

@khellang
Copy link
Member

khellang commented Dec 8, 2016

I'll commit to work with you on this asap if you're up for it :P

Yes! New year, new bootstrapper 😁

@p-m-j
Copy link

p-m-j commented Oct 2, 2019

Is this project dead?

Did nancy-bootstrapper-prototype get parked?

Edit: In the meantime here's a hack to allow moderately painless usage of the code from this repo with autfoac 4.9.x

Warning this has had all of 5 minutes testing

#pragma warning disable CS0618 // Type or member is obsolete (I KNOWWWWW!)
#pragma warning disable SA1402 // File may only contain a single type
public static class AutofacExtensions
{
    public static IContainer Update(this IContainer container, Action<ContainerBuilder> builderAction)
    {
        var builder = new ContainerBuilder();
        builderAction(builder);
        builder.Update(container);
        return container;
    }
}
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore SA1402 // File may only contain a single type

`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants