Autofac in web applications, where should I store the container for easy access?

前端 未结 5 1054
难免孤独
难免孤独 2020-12-08 23:16

I\'m still pretty new to using Autofac and one thing I miss in the documentation and examples is how to make it easy to get to the configured container from different places

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 23:50

    Peter Lillevold's response above is correct - you can access the container from any component by taking a dependency on the IContext interface.

    If you really do need the actual container reference, see Autofac.Integration.Web.IContainerProviderAccessor.

提交回复
热议问题