Example #1
0
        public override IMutablePicoContainer MakeChildContainer()
        {
            ImplementationHidingPicoContainer pc = new ImplementationHidingPicoContainer(caf, this, lifecycleManager);

            DelegateContainer.AddChildContainer(pc);
            return(pc);
        }
Example #2
0
        private DelegateContainer AddInternal(ServiceDescriptor serviceDescriptor)
        {
            AutoDIServiceDescriptor autoDIDescriptor = serviceDescriptor as AutoDIServiceDescriptor;
            Lifetime lifetime   = autoDIDescriptor?.AutoDILifetime ?? serviceDescriptor.Lifetime.ToAutoDI();
            Type     targetType = autoDIDescriptor?.TargetType;

            var container = new DelegateContainer(lifetime, targetType, GetFactory(serviceDescriptor));

            _accessors[serviceDescriptor.ServiceType] = container;

            return(container);

            Func <IServiceProvider, object> GetFactory(ServiceDescriptor descriptor)
            {
                if (descriptor.ImplementationType != null)
                {
                    //TODO, resolve parameters
                    return(sp => Activator.CreateInstance(descriptor.ImplementationType));
                }
                if (descriptor.ImplementationFactory != null)
                {
                    return(descriptor.ImplementationFactory);
                }
                //NB: separate the instance from the ServiceDescriptor to avoid capturing both
                object instance = descriptor.ImplementationInstance;

                return(_ => instance);
            }
        }
Example #3
0
    static void Main()
    {
        DelegateContainer <MyDelegate> delegates =
            new DelegateContainer <MyDelegate>();

        delegates.Add(EntryPoint.PrintInt);
    }
        static void Main(string[] args)
        {
            /*
             * Deletages Tasks
             */
            DelegateContainer.del();
            Console.WriteLine(DelegateContainer.floatDel());
            DelegateContainer.intakeDel("yeetus", "deletus", "the fetus");

            //Bonus task:
            AddDel      addDel      = MathClass.Add;
            AddFloatDel addFloatDel = MathClass.Add;

            Console.WriteLine(addDel(1, 4));
            Console.WriteLine(addFloatDel(1.5f, 4.2f));


            /*
             * Lambda Tasks
             */
            LambdaTwoTimes lambdaTwoTimes = (a) => a * 2;

            Console.WriteLine(lambdaTwoTimes(4));

            LambdaFloatSum lambdaFloatSum = (a, b, c) => a + b + c;

            Console.WriteLine(lambdaFloatSum(2.4f, 2.6f, 7.3f));

            LambdaString lambdaString = () => "Hello world";

            Console.WriteLine(lambdaString());
        }
Example #5
0
        public static void GenericDelegateContainerTest()
        {
            var delegates = new DelegateContainer <int>();

            delegates.Add(PrintInt);
            delegates.CallDelegates(55);
            delegates.CallDelegates(33);
            delegates.CallDelegates(44);
Example #6
0
    static void Main()
    {
        DelegateContainer <int> delegates =
            new DelegateContainer <int>();

        delegates.Add(EntryPoint.PrintInt);
        delegates.CallDelegates(42);
    }
Example #7
0
        //Формирует контейнер с функциями, которые нужны для отрисовки фигур
        private DelegateContainer GetDeleateContainer()
        {
            DelegateContainer dlc = new DelegateContainer();

            dlc.fGetGraphics  = new DelegateContainer.dGetGraphics(GetGraphics);
            dlc.fRealToSreeen = new DelegateContainer.dRealToScreen(RealToScreen);
            dlc.fScreenToReal = new DelegateContainer.dScreenToReal(ScreenToReal);

            return(dlc);
        }
Example #8
0
 public override IComponentAdapter RegisterComponentImplementation(Object componentKey,
                                                                   Type componentImplementation)
 {
     if (componentKey is Type)
     {
         Type clazz = (Type)componentKey;
         if (clazz.IsInterface)
         {
             IComponentAdapter caDelegate =
                 caf.CreateComponentAdapter(componentKey, componentImplementation, null);
             return
                 (DelegateContainer.RegisterComponent(new ImplementationHidingComponentAdapter(caDelegate, true)));
         }
     }
     return(DelegateContainer.RegisterComponentImplementation(componentKey, componentImplementation));
 }
 public override IComponentAdapter RegisterComponentImplementation(Object componentKey,
                                                                   Type componentImplementation,
                                                                   IParameter[] parameters)
 {
     if (componentKey is Type)
     {
         Type clazz = (Type)componentKey;
         if (clazz.IsInterface)
         {
             IComponentAdapter caDelegate =
                 caf.CreateComponentAdapter(componentKey, componentImplementation, parameters);
             ImplementationHidingComponentAdapter ihDelegate =
                 new ImplementationHidingComponentAdapter(caDelegate, true);
             return(DelegateContainer.RegisterComponent(new CachingComponentAdapter(ihDelegate)));
         }
     }
     return(DelegateContainer.RegisterComponentImplementation(componentKey, componentImplementation, parameters));
 }
Example #10
0
        public void Add(IServiceCollection services)
        {
            //TODO: This re-grouping seems off somewhere...
            foreach (IGrouping <Type, ServiceDescriptor> serviceDescriptors in from ServiceDescriptor service in services
                     let autoDIService = service as AutoDIServiceDescriptor
                                         group service by autoDIService?.TargetType
                                         into @group
                                         select @group
                     )
            {
                DelegateContainer container = null;
                foreach (ServiceDescriptor serviceDescriptor in serviceDescriptors)
                {
                    //Build up the container if it has not been generated or we do not have multiple AutoDI target types
                    if (container == null || serviceDescriptors.Key == null)
                    {
                        container = AddInternal(serviceDescriptor);
                    }

                    _accessors[serviceDescriptor.ServiceType] = container;
                }
            }
        }
Example #11
0
        public void Delegate_With_MemoryStream()
        {
            using (var stream = new MemoryStream())
            {
                {
                    var container = new DelegateContainer();

                    container.Owner = new DelegateOwner();
                    container.User  = new DelegateUser();

                    container.Owner.Event += container.User.EventHappened;

                    var writer = new ObjectWriter(stream);
                    writer.Write(container);
                }

                var reader        = new ObjectReader(stream);
                var readContainer = reader.Read() as DelegateContainer;

                Assert.AreEqual(readContainer.Owner.GetDelegate().Target, readContainer.User);
                Assert.AreEqual(readContainer.Owner.GetDelegate().Target.GetType(), typeof(DelegateUser));
                Assert.AreEqual(readContainer.Owner.GetDelegate().Method.Name, "EventHappened");
            }
        }
 public ExternPersistentContainer(Card c, DelegateContainer.ObjectParam f)
 {
     OwnerCard = c;
     func = f;
 }
 public void AddExternPersistent(Card c, DelegateContainer.ObjectParam func)
 {
     ExternPersistent.Add(new ExternPersistentContainer(c, func));
 }
Example #14
0
 public TaskItem(IDownloader downloader, DelegateContainer delegates)
 {
     resourceDownloader   = downloader;
     downloader.delegates = delegates;
 }