private void Awake() { // gameObject.GetContext() is an extension method, which ties to find the closest ComponentContext component var context = gameObject.GetContext(); // Resolve services according FooConfiguration fooService1 = context.Resolve <IFooService1>(); fooService2 = context.Resolve <IFooService2>(); }
private void Awake() { // gameObject.GetContext() is an extension method, which ties to find the closest ComponentContext component var context = gameObject.GetContext(); // Resolve services according FooConfiguration // According to FooConfiguration, IFooService2 is registered as InstancePerDependency. // Hence, 'context.Resolve<IFooService2>()' creates new instance of FooService2, according to FooConfiguration fooService1 = context.Resolve <IFooService1>(); fooService2 = context.Resolve <IFooService2>(); }
private void Awake() { var context = gameObject.GetContext(); // Resolve services according FooConfiguration fooService1 = context.Resolve <IFooService1>(); // According FooConfiguration, IFooService2 is registered as InstancePerDependency, but // AddChild<FooChildOfChildController>(b => // { // b.RegisterInstance(fooService2).As<IFooService2>(); // }); // overrides registration of IFooService2 // Hence, fooService2 will be the same as fooService2 of FooChildController fooService2 = context.Resolve <IFooService2>(); }