public SignalCopyBinder From(Action <ConcreteBinderGeneric <TObject> > objectBindCallback) { Assert.That(!_bindStatement.HasFinalizer); _bindStatement.SetFinalizer(new NullBindingFinalizer()); var objectLookupId = Guid.NewGuid(); // Very important here that we use NoFlush otherwise the main binding will be finalized early var objectBinder = _container.BindNoFlush <TObject>().WithId(objectLookupId); objectBindCallback(objectBinder); // We need to do this to make sure SignalCallbackWithLookupWrapper does not have // generic types to avoid AOT issues Func <object, Action <object> > methodGetterMapper = obj => s => _methodGetter((TObject)obj)((TSignal)s); var wrapperBinder = _container.Bind <IDisposable>() .To <SignalCallbackWithLookupWrapper>() .AsCached() .WithArguments(_signalBindInfo, typeof(TObject), objectLookupId, methodGetterMapper) .NonLazy(); var copyBinder = new SignalCopyBinder(wrapperBinder.BindInfo); // Make sure if they use one of the Copy/Move methods that it applies to both bindings copyBinder.AddCopyBindInfo(objectBinder.BindInfo); return(copyBinder); }
public SignalCopyBinder From(Action <ConcreteBinderGeneric <TObject> > objectBindCallback) { Assert.IsNull(_finalizerWrapper.SubFinalizer); _finalizerWrapper.SubFinalizer = new NullBindingFinalizer(); var objectLookupId = Guid.NewGuid(); // Very important here that we use NoFlush otherwise the main binding will be finalized early var objectBinder = _container.BindNoFlush <TObject>().WithId(objectLookupId); objectBindCallback(objectBinder); var wrapperBinder = _container.Bind <IDisposable>() .To <SignalCallbackWithLookupWrapper <TObject, TSignal> >() .AsCached() .WithArguments(_methodGetter, objectLookupId) .NonLazy(); var copyBinder = new SignalCopyBinder(wrapperBinder.BindInfo); // Make sure if they use one of the Copy/Move methods that it applies to both bindings copyBinder.AddCopyBindInfo(objectBinder.BindInfo); return(copyBinder); }