Пример #1
0
        public object CreateInstance(Type requestedType)
        {
            if (requestedType == null)
            {
                throw new ArgumentNullException("requestedType");
            }
            else
            {
                object         retInst = null;
                ILifetimeScope scope   = null;

                if ((requestedType.IsInterface || requestedType.IsAbstract) && (!_iocContainer.ComponentRegistry.IsRegistered(new TypedService(requestedType))))
                {
                    throw new ConcreteTypeResolutionException(requestedType, string.Format("Missing IoC Type Registration for type '{0}'.", requestedType.FullName));
                }
                else if (!_iocContainer.ComponentRegistry.IsRegistered(new TypedService(requestedType)))
                {
                    retInst = MethodCaller.CreateInstance(requestedType);
                }
                else
                {
                    scope   = _iocContainer.BeginLifetimeScope();
                    retInst = scope.Resolve(requestedType);
                }

                var scopeRetInst = retInst as IBusinessScope;

                if (scopeRetInst != null)
                {
                    scopeRetInst.Scope = scope ?? _iocContainer.BeginLifetimeScope();
                }
                return(retInst);
            }
        }
        /// <summary>
        /// Creates a serialization formatter object.
        /// </summary>
        public static ISerializationFormatter GetFormatter()
        {
#if !NET5_0
            if (ApplicationContext.SerializationFormatter == ApplicationContext.SerializationFormatters.BinaryFormatter)
            {
                return(new BinaryFormatterWrapper());
            }
#if !NETSTANDARD2_0
            else if (ApplicationContext.SerializationFormatter == ApplicationContext.SerializationFormatters.NetDataContractSerializer)
            {
                return(new NetDataContractSerializerWrapper());
            }
#endif
            else
#endif
            if (ApplicationContext.SerializationFormatter == ApplicationContext.SerializationFormatters.CustomFormatter)
            {
                string customFormatterTypeName = ConfigurationManager.AppSettings["CslaSerializationFormatter"];
                return((ISerializationFormatter)MethodCaller.CreateInstance(Type.GetType(customFormatterTypeName, true, true)));
            }
            else
            {
                return(new Csla.Serialization.Mobile.MobileFormatter());
            }
        }
Пример #3
0
        /// <summary>
        /// Creates the DataPortalProxy to use for DataPortal call on the objectType.
        /// </summary>
        /// <param name="objectType">Root business object type</param>
        /// <returns></returns>
        public IDataPortalProxy Create(Type objectType)
        {
            if (DataPortalTypeProxyDescriptors != null)
            {
                if (DataPortalTypeProxyDescriptors.TryGetValue(GetTypeKey(objectType), out DataPortalProxyDescriptor descriptor))
                {
                    var type = Type.GetType(descriptor.ProxyTypeName);
                    return((IDataPortalProxy)Activator.CreateInstance(type, descriptor.DataPortalUrl));
                }
            }

            if (_proxyType == null)
            {
                string proxyTypeName = ApplicationContext.DataPortalProxy;
                if (proxyTypeName == "Local")
                {
                    _proxyType = typeof(LocalProxy);
                }
                else
                {
                    _proxyType = Type.GetType(proxyTypeName, true, true);
                }
            }
            return((IDataPortalProxy)MethodCaller.CreateInstance(_proxyType));
        }
Пример #4
0
        // OR use Constructor injection
        //[ImportingConstructor]
        //public CustomerFactory(ICustomerInfoFactory customerInfoFactory)
        //{
        //  MyCustomerInfoFactory = customerInfoFactory;
        //}

        public object Fetch(string criteria)
        {
            var list = (CustomerList)MethodCaller.CreateInstance(typeof(CustomerList));


            // just sets up some mock data - could com from Xml,L2S, EF or othere sources unknown to the BO itself.
            var customers = new[]
            {
                new CustomerData {
                    Id = 1, Name = "Baker, Jonathan"
                },
                new CustomerData {
                    Id = 2, Name = "Peterson, Peter"
                },
                new CustomerData {
                    Id = 3, Name = "Olsen, Egon"
                },
                new CustomerData {
                    Id = 4, Name = "Hansen, hans"
                }
            };

            list.RaiseListChangedEvents = false;
            SetIsReadOnly(list, false);

            // tranform to my lists child type
            list.AddRange(customers.Select(p => MyCustomerInfoFactory.GetCustomerInfo(p)));

            SetIsReadOnly(list, true);
            list.RaiseListChangedEvents = true;

            return(list);
        }
Пример #5
0
        private OrderInfo GetOrderInfo(int id, string customerName)
        {
            var obj = (OrderInfo)MethodCaller.CreateInstance(typeof(OrderInfo));

            LoadProperty(obj, OrderInfo.IdProperty, id);
            LoadProperty(obj, OrderInfo.CustomerNameProperty, customerName);
            return(obj);
        }
Пример #6
0
        public object CreateInstance(Type requestedType)
        {
            if (requestedType == null)
            {
                throw new ArgumentNullException(nameof(requestedType));
            }

            return(MethodCaller.CreateInstance(requestedType));
        }
Пример #7
0
        public LineItem Create()
        {
            var obj = (LineItem)MethodCaller.CreateInstance(typeof(LineItem));

            MarkAsChild(obj);
            MarkNew(obj);
            CheckRules(obj);
            return(obj);
        }
        public CustomerInfo GetCustomerInfo(DataEntitites.CustomerData data)
        {
            var customer = (CustomerInfo)MethodCaller.CreateInstance(typeof(CustomerInfo));

            LoadProperty(customer, CustomerInfo.IdProperty, data.Id);
            LoadProperty(customer, CustomerInfo.NameProperty, data.Name);

            return(customer);
        }
Пример #9
0
        public Order Create()
        {
            var obj = (Order)MethodCaller.CreateInstance(typeof(Order));

            LoadProperty(obj, Order.IdProperty, -1);
            MarkNew(obj);
            CheckRules(obj);
            return(obj);
        }
Пример #10
0
        /// <summary>
        /// Creates the DataPortalProxy to use for DataPortal call on the objectType.
        /// </summary>
        /// <param name="objectType">Root business object type</param>
        /// <returns></returns>
        public IDataPortalProxy Create(Type objectType)
        {
            if (DataPortalTypeProxyDescriptors != null)
            {
                if (DataPortalTypeProxyDescriptors.TryGetValue(GetTypeKey(objectType), out DataPortalProxyDescriptor descriptor))
                {
                    var type = Type.GetType(descriptor.ProxyTypeName);
#if !NET40 && !NET45
                    if (ApplicationContext.ScopedServiceProvider != null)
                    {
                        var httpClient = ApplicationContext.ScopedServiceProvider.GetService(typeof(System.Net.Http.HttpClient));
                        if (httpClient == null)
                        {
                            return((IDataPortalProxy)MethodCaller.CreateInstance(type, descriptor.DataPortalUrl));
                        }
                        else
                        {
                            return((IDataPortalProxy)MethodCaller.CreateInstance(_proxyType, httpClient, descriptor.DataPortalUrl));
                        }
                    }
                    else
                    {
                        return((IDataPortalProxy)MethodCaller.CreateInstance(type, descriptor.DataPortalUrl));
                    }
#else
                    return((IDataPortalProxy)Activator.CreateInstance(type, descriptor.DataPortalUrl));
#endif
                }
            }

            if (_proxyType == null)
            {
                string proxyTypeName = ApplicationContext.DataPortalProxy;
                if (proxyTypeName == "Local")
                {
                    _proxyType = typeof(LocalProxy);
                }
                else
                {
                    _proxyType = Type.GetType(proxyTypeName, true, true);
                }
            }
#if !NET40 && !NET45
            var provider = ApplicationContext.ScopedServiceProvider;
            if (provider == null)
            {
                return((IDataPortalProxy)MethodCaller.CreateInstance(_proxyType));
            }
            else
            {
                return((IDataPortalProxy)Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(provider, _proxyType));
            }
#else
            return((IDataPortalProxy)MethodCaller.CreateInstance(_proxyType));
#endif
        }
Пример #11
0
        public void FetchOrderItems(Order item)
        {
            try
            {
                using (XRMSEntities context = new XRMSEntities())
                {
                    _uow = new UnitOfWork(context, new RepositoryProvider(RepositoryFactories.Instance()));
                    if (item != null)
                    {
                        // get order items
                        decimal subTotalPrice = 0;
                        using (BypassPropertyChecks(item))
                        {
                            var obj = (OrderItemList)MethodCaller.CreateInstance(typeof(OrderItemList));
                            //var obj = (OrderItemList) DataPortal.CreateChild<OrderItemList>();
                            MarkAsChild(obj);
                            var rlce = obj.RaiseListChangedEvents;
                            obj.RaiseListChangedEvents = false;
                            List <OrderItem> itemList = _uow.OrderItemRepository.GetBy(o => o.OrderId == item.Id).ToList();
                            // get material info of each orderItem item
                            foreach (OrderItem detail in itemList)
                            {
                                detail.ProductInfo      = _uow.ProductRepository.GetById(detail.ProductId);
                                detail.ProductInfo.Unit = _uow.UnitRepository.GetById(detail.ProductInfo.UnitId);
                                detail.SetOldQuantity();
                                detail.EdittedQuantity = 0;
                                MarkOld(detail);
                                MarkAsChild(detail);
                                obj.Add(detail);
                                //item.Recipes.Add(detail);
                                if (detail.IsCancelled != true)
                                {
                                    subTotalPrice += detail.ItemPrice;
                                }
                            }
                            obj.RaiseListChangedEvents = rlce;
                            LoadProperty(item, Order.OrderItemsProperty, obj);
                            //MarkAsChild(item.Recipes);
                        }

                        item.SubTotalPrice = subTotalPrice;

                        /*item.VatPrice = item.VatEnable ? (item.SubTotalPrice * 10 / 100) : 0;
                         * item.DiscountPrice = (-1) * (item.SubTotalPrice * item.DiscountPercent / 100);
                         * item.TotalPrice = item.SubTotalPrice + item.VatPrice + item.DiscountPrice + item.SpecialDiscount + item.ServiceCharge;
                         * item.Change = item.Cash - item.TotalPrice;*/

                        item.MarkOld();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
        }
Пример #12
0
        public OrderList FetchList()
        {
            var obj = (OrderList)MethodCaller.CreateInstance(typeof(OrderList));

            obj.RaiseListChangedEvents = false;

            obj.AddRange(from r in MockDb.Orders
                         select GetOrderInfo(r.Id, r.CustomerName));

            obj.RaiseListChangedEvents = true;
            return(obj);
        }
Пример #13
0
        public object Fetch(object criteria)
        {
            var root = (MyRoot)MethodCaller.CreateInstance(typeof(MyRoot));

            using (BypassPropertyChecks(root))
            {
                root.Id   = 2;
                root.Name = "Jonny";
            }

            return(root);
        }
Пример #14
0
        private LineItem GetLineItem(int id, string name)
        {
            var obj = (LineItem)MethodCaller.CreateInstance(typeof(LineItem));

            MarkAsChild(obj);
            using (BypassPropertyChecks(obj))
            {
                LoadProperty(obj, LineItem.IdProperty, id);
                LoadProperty(obj, LineItem.NameProperty, name);
            }
            MarkOld(obj);
            return(obj);
        }
Пример #15
0
        public object Create()
        {
            var root = (MyRoot)MethodCaller.CreateInstance(typeof(MyRoot));


            using (BypassPropertyChecks(root))
            {
                root.Id   = -1;
                root.Name = "New";
            }

            return(root);
        }
Пример #16
0
        public OrderInfo FetchInfo(int id)
        {
            var obj  = (OrderInfo)MethodCaller.CreateInstance(typeof(OrderInfo));
            var item = (from r in MockDb.Orders
                        where r.Id == id
                        select r).First();

            LoadProperty(obj, OrderInfo.IdProperty, item.Id);
            LoadProperty(obj, OrderInfo.CustomerNameProperty, item.CustomerName);
            var itemCount = MockDb.LineItems.Where(r => r.OrderId == item.Id).Count();

            LoadProperty(obj, OrderInfo.LineItemCountProperty, itemCount);
            return(obj);
        }
Пример #17
0
        public object CreateInstance(Type requestedType)
        {
            if (requestedType == null)
            {
                throw new ArgumentNullException("requestedType");
            }

#if DEBUG
            Debug.WriteLine(string.Format("{0} instance is being created.", requestedType.ToString()));
#endif

            // this is exactly what the default activator does
            return(MethodCaller.CreateInstance(getConcreteType(requestedType)));
        }
Пример #18
0
        internal LineItems FetchItems(int orderId)
        {
            var obj  = (LineItems)MethodCaller.CreateInstance(typeof(LineItems));
            var rlce = obj.RaiseListChangedEvents;

            obj.RaiseListChangedEvents = false;

            obj.AddRange(from r in MockDb.LineItems
                         where r.OrderId == orderId
                         select GetLineItem(r.Id, r.Name));

            obj.RaiseListChangedEvents = rlce;
            return(obj);
        }
Пример #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static IConfigSource Create(string name)
        {
            Check.Argument.IsNotNull("name", name);

            ConfigSettings        configSettings  = FrameworkConfig.GetConfig <ConfigSettings>();
            ConfigProviderMapping providerMapping = configSettings.GetProviderMapping(name);
            IConfigSource         configSource    = MethodCaller.CreateInstance(providerMapping.Type) as IConfigSource;

            if (configSource == null)
            {
                ConfigThrowHelper.ThrowConfigException(R.ConfigSourceNotFound, name);
            }

            return(configSource);
        }
Пример #20
0
        public object CreateInstance(Type requestedType)
        {
            if (requestedType.IsGenericType && typeof(IMobileObjectWrapper).IsAssignableFrom(requestedType))
            {
                var scope = Container.BeginLifetimeScope();
                var func  = scope.Resolve(typeof(Func <,>).MakeGenericType(new Type[] { typeof(ILifetimeScope), requestedType }));

                var mow = ((Func <ILifetimeScope, IMobileObjectWrapper>)func)(scope);

                return(mow);
            }
            else
            {
                return(MethodCaller.CreateInstance(requestedType));
            }
        }
Пример #21
0
        public void FetchProductRecipes(Product item)
        {
            try
            {
                using (XRMSEntities context = new XRMSEntities())
                {
                    _uow = new UnitOfWork(context, new RepositoryProvider(RepositoryFactories.Instance()));
                    if (item != null)
                    {
                        // get recipes
                        using (BypassPropertyChecks(item))
                        {
                            var obj = (RecipeItemList)MethodCaller.CreateInstance(typeof(RecipeItemList));
                            //var obj = (RecipeItemList) DataPortal.CreateChild<RecipeItemList>();
                            MarkAsChild(obj);
                            var rlce = obj.RaiseListChangedEvents;
                            obj.RaiseListChangedEvents = false;
                            List <RecipeItem> itemList = _uow.RecipeItemRepository.GetBy(o => o.ProductId == item.Id).ToList();
                            // get material info of each recipe item
                            foreach (RecipeItem detail in itemList)
                            {
                                detail.MaterialInfo      = _uow.MaterialRepository.GetById(detail.MaterialId);
                                detail.MaterialInfo.Unit = _uow.UnitRepository.GetById(detail.MaterialInfo.UnitId);
                                MarkOld(detail);
                                MarkAsChild(detail);
                                obj.Add(detail);
                                //item.Recipes.Add(detail);
                            }
                            obj.RaiseListChangedEvents = rlce;
                            LoadProperty(item, Product.RecipesProperty, obj);
                            //MarkAsChild(item.Recipes);
                        }

                        item.MarkOld();
                    }
                    else
                    {
                        throw new ArgumentNullException("item");
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
        }
        /// <summary>
        /// Creates the DataPortalProxy to use for DataPortal call on the objectType.
        /// </summary>
        /// <param name="objectType"></param>
        /// <returns></returns>
        public IDataPortalProxy Create(Type objectType)
        {
            if (_proxyType == null)
            {
                string proxyTypeName = ApplicationContext.DataPortalProxy;
                if (proxyTypeName == "Local")
                {
                    _proxyType = typeof(LocalProxy);
                }
                else
                {
                    _proxyType = Type.GetType(proxyTypeName, true, true);
                }
            }

            return((IDataPortalProxy)MethodCaller.CreateInstance(_proxyType));
        }
Пример #23
0
        public Order Fetch(int id)
        {
            var obj  = (Order)MethodCaller.CreateInstance(typeof(Order));
            var item = (from r in MockDb.Orders
                        where r.Id == id
                        select r).First();

            using (BypassPropertyChecks(obj))
            {
                LoadProperty(obj, Order.IdProperty, item.Id);
                LoadProperty(obj, Order.CustomerNameProperty, item.CustomerName);
                var lif = new LineItemFactory();
                LoadProperty(obj, Order.LineItemsProperty, lif.FetchItems(id));
            }
            MarkOld(obj);
            return(obj);
        }
Пример #24
0
 public virtual T Create()
 {
     return((T)MethodCaller.CreateInstance(typeof(T)));
 }
Пример #25
0
 public object CreateInstance(Type requestedType)
 {
     return(MethodCaller.CreateInstance(requestedType));
 }