Say you have some code that only allows you to set a property through a method rather than through a formal property (for whatever reason).public interface IOrderSystem{void MakeOrder(Order o);}public class OrderSystem : IOrderSystem{public IRepository OrderRepository { get; private set; }public void SetRepository(IRepository repo){this.OrderRepository = repo;}public void MakeOrder(Order o){this.OrderRepository.AddOrder(o);}}
Given a situation like that, you can't use constructor or property injection, but you can still take advantage of the method to automatically wire up the repository to the order system.var builder = new ContainerBuilder();builder.RegisterType<Repository>().As<IRepository>();builder.Register<OrderSystem>().As<IOrderSystem>().OnActivating(e => {var repo = e.Context.Resolve<IRepository>();e.Instance.SetRepository(repo);});var container = builder.Build();// The repo will already be set on the order system with no additional work:var orderSystem = container.Resolve<IOrderSystem>();
--
You received this message because you are subscribed to the Google Groups "Autofac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autofac+u...@googlegroups.com.
To post to this group, send email to aut...@googlegroups.com.
Visit this group at http://groups.google.com/group/autofac.
For more options, visit https://groups.google.com/groups/opt_out.
Temporal Coupling is a bad practice IMHO, Mark Seemann explains why. I wouldn't support this feature :)