示例#1
0
        public SignalCopyBinder ToMethod(Action <TSignal> callback)
        {
            Assert.That(!_bindStatement.HasFinalizer);
            _bindStatement.SetFinalizer(new NullBindingFinalizer());

            var bindInfo = _container.Bind <IDisposable>()
                           .To <SignalCallbackWrapper>()
                           .AsCached()
                           // Note that there's a reason we don't just make SignalCallbackWrapper have a generic
                           // argument for signal type - because when using struct type signals it throws
                           // exceptions on AOT platforms
                           .WithArguments(_signalBindInfo, (Action <object>)(o => callback((TSignal)o)))
                           .NonLazy().BindInfo;

            return(new SignalCopyBinder(bindInfo));
        }
        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);
        }
示例#3
0
        public SubContainerBinder(
            BindInfo bindInfo,
            BindStatement bindStatement,
            object subIdentifier, bool resolveAll)
        {
            _bindInfo      = bindInfo;
            _bindStatement = bindStatement;
            _subIdentifier = subIdentifier;
            _resolveAll    = resolveAll;

            // Reset in case the user ends the binding here
            bindStatement.SetFinalizer(null);
        }