Commits

Christian Dalager committed 0cd00d3

Minor last minute improvements, code formatting and stuff.

  • Participants
  • Parent commits 9fac490

Comments (0)

Files changed (7)

DependencyInjection/WebApp/Helpers/AutoMapperBootstrapper.cs

-using System;
 using AutoMapper;
 using Model.Entities;
-using Model.Interfaces;
-using WebApp.Controllers;
 using WebApp.Models;
-using System.Web.Mvc;
 
 namespace WebApp.Helpers
 {
-    public class AutoMapperBootstrapper
-    {
-        public static void Initialize()
-        {
-            Mapper.Initialize(cfg=>
-                                  {
-                                      cfg.AddProfile<ViewModelProfile>();
-                                  }
-                );
-            Mapper.AssertConfigurationIsValid();
-        }
-    }
+	public class AutoMapperBootstrapper
+	{
+		public static void Initialize()
+		{
+			Mapper.Initialize(cfg => { cfg.AddProfile<ViewModelProfile>(); }
+				);
+			Mapper.AssertConfigurationIsValid();
+		}
+	}
 
-    public class ViewModelProfile:Profile
-    {
-        protected override void Configure()
-        {
-            CreateMap<Product, ProductEditModel>().ForMember(x => x.Categories, opt => opt.Ignore());
-            CreateMap<Product, ProductShowModel>();
-            CreateMap<Product, ProductListModel>().ForMember(x=>x.Description,c=>c.MapFrom(x=>Truncate(x.Description,50)));
-        }
+	public class ViewModelProfile : Profile
+	{
+		protected override void Configure()
+		{
+			CreateMap<Product, ProductEditModel>()
+				.ForMember(x => x.Categories, opt => opt.Ignore());
+			CreateMap<Product, ProductShowModel>();
+			CreateMap<Product, ProductListModel>()
+				.ForMember(x => x.Description, c => c.MapFrom(x => Truncate(x.Description, 50)));
+		}
 
-        private string Truncate(string desc,int length=30)
-        {
-            if (desc.Length > length)
-            {
-                return desc.Substring(0, length) + "...";
-            }
-            return desc;
-        }
-    }
+		private string Truncate(string desc, int length = 30)
+		{
+			if (desc.Length > length)
+			{
+				return desc.Substring(0, length) + "...";
+			}
+			return desc;
+		}
+	}
 }

DependencyInjection/WebApp/Helpers/IoC.cs

+using System;
+using System.Linq;
+using System.IO;
+using System.Diagnostics;
+using System.Reflection;
+using System.Web.Mvc;
+using Castle.Core;
+using Castle.Windsor;
+using Castle.Windsor.Configuration.Interpreters;
+
+namespace WebApp
+{
+    /// <summary>
+    /// IoC Helper Class
+    /// 
+    /// Derived from Codecamp server: http://code.google.com/p/codecampserver/
+    /// </summary>
+    public static class IoC
+    {
+        private static IWindsorContainer _container;
+
+        private static readonly object _lockDummy = new object();
+        private static bool _initiliazed;
+
+        public const string CONFIGFILE = @"Windsor.config.xml";
+
+        private static void EnsureInitialized()
+        {
+            if (!_initiliazed)
+            {
+                lock (_lockDummy)
+                {
+                    if (!_initiliazed)
+                    {
+                        var basePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
+
+                        var configPath = Path.Combine(basePath, CONFIGFILE);
+
+
+                        if (!File.Exists(configPath))
+                        {
+                            basePath = basePath + @"bin\";
+                            configPath = Path.Combine(basePath, CONFIGFILE);
+                            if(File.Exists(configPath))
+                            {
+                                var configInterpreter = new XmlInterpreter(configPath);
+                                InitializeWith(new WindsorContainer(configInterpreter));   
+                            }else
+                            {
+                                InitializeWith(new WindsorContainer());
+                            }
+                        }
+
+                        Debug.WriteLine(string.Format("Trying to load windsor config from '{0}'", configPath));
+
+                        
+                        _initiliazed = true;
+                    }
+                }
+            }
+        }
+
+        public static void InitializeWith(IWindsorContainer container)
+        {
+            _container = container;
+            _initiliazed = true;
+        }
+
+        public static T Resolve<T>()
+        {
+            EnsureInitialized();
+            return _container.Resolve<T>();
+        }
+
+        public static T Resolve<T>(string key)
+        {
+            EnsureInitialized();
+            return _container.Resolve<T>(key);
+        }
+
+        public static IWindsorContainer GetContainer()
+        {
+            EnsureInitialized();
+            return _container;
+        }
+
+        public static void Reset()
+        {
+            if (_container != null)
+            {
+                _container.Dispose();
+                _container = null;
+            }
+        }
+
+        /// <summary>
+        /// Register controllers with DI container
+        /// </summary>
+        public static void RegisterControllersInContainer(Assembly assembly)
+        {
+            EnsureInitialized();
+
+            //add all controllers
+            foreach (var type in assembly.GetTypes())
+            {
+                if (!(typeof(IController).IsAssignableFrom(type) && type.IsClass)) continue;
+                var typekey = type.FullName.ToLowerInvariant();
+                Debug.WriteLine(string.Format("Registering controller '{0}' in container with key '{1}'", type.Name, typekey));
+                Register(typekey, type, LifestyleType.Transient);
+            }
+        }
+
+        /// <summary>
+        /// Registers all the types in the servicesNamespace that can be found in the assembly.
+        /// The first interface, in the form I[Service type name] found is used.
+        /// </summary>
+        /// <param name="assembly"></param>
+        /// <param name="servicesNamespace"></param>
+        public static void AutoRegisterTypesInContainer(Assembly assembly, string servicesNamespace)
+        {
+            AutoRegisterTypesInContainer(assembly, servicesNamespace, false);
+        }
+        public static void AutoRegisterTypesInContainer(Assembly assembly, string servicesNamespace, bool registerServiceIfNoInterface)
+        {
+            // Windsor mass component registration
+            EnsureInitialized();
+
+            //add all controllers
+            foreach (var type in assembly.GetTypes())
+            {
+                // If type is of registerType
+                if (type.IsClass && (string.IsNullOrEmpty(servicesNamespace)
+                                     || (type.Namespace != null && type.Namespace.StartsWith(servicesNamespace))))
+                {
+                    var typekey = type.FullName.ToLowerInvariant();
+
+                    // Look for an interface with the I[Type name]
+                    var typeName = type.Name;
+                    var firstInterface = type.GetInterfaces().FirstOrDefault(intface => intface.Name.Contains(typeName));
+                    if (firstInterface != null)
+                    {
+                        Register(typekey, firstInterface, type, LifestyleType.Transient);
+                    }
+                    else if (registerServiceIfNoInterface)
+                    {
+                        Register(typekey, type, LifestyleType.Transient);
+                    }
+
+                    Debug.WriteLine(string.Format("Registering '{0}' in container with key '{1}' as it is in '{2}'", type.Name, typekey, servicesNamespace));
+                }
+            }
+        }
+
+        public static void Register(Type classType, LifestyleType lifestyleType)
+        {
+            EnsureInitialized();
+
+            var typekey = classType.FullName.ToLowerInvariant();
+            _container.AddComponentLifeStyle(typekey, classType, lifestyleType);
+        }
+        public static void Register(string typeKey, Type classType, LifestyleType lifestyleType)
+        {
+            EnsureInitialized();
+            _container.AddComponentLifeStyle(typeKey, classType, lifestyleType);
+        }
+        public static void Register(string typeKey, Type serviceType, Type classType, LifestyleType lifestyleType)
+        {
+            EnsureInitialized();
+            _container.AddComponentLifeStyle(typeKey, serviceType, classType, lifestyleType);
+        }
+        public static Boolean Remove(string typeKey)
+        {
+            EnsureInitialized();
+
+            return _container.Kernel.RemoveComponent(typeKey);
+        }
+    }
+}

DependencyInjection/WebApp/IoC.cs

-using System;
-using System.Linq;
-using System.IO;
-using System.Diagnostics;
-using System.Reflection;
-using System.Web.Mvc;
-using Castle.Core;
-using Castle.Windsor;
-using Castle.Windsor.Configuration.Interpreters;
-
-namespace WebApp
-{
-    /// <summary>
-    /// IoC Helper Class
-    /// 
-    /// Derived from Codecamp server: http://code.google.com/p/codecampserver/
-    /// </summary>
-    public static class IoC
-    {
-        private static IWindsorContainer _container;
-
-        private static readonly object _lockDummy = new object();
-        private static bool _initiliazed;
-
-        public const string CONFIGFILE = @"Windsor.config.xml";
-
-        private static void EnsureInitialized()
-        {
-            if (!_initiliazed)
-            {
-                lock (_lockDummy)
-                {
-                    if (!_initiliazed)
-                    {
-                        var basePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
-
-                        var configPath = Path.Combine(basePath, CONFIGFILE);
-
-
-                        if (!File.Exists(configPath))
-                        {
-                            basePath = basePath + @"bin\";
-                            configPath = Path.Combine(basePath, CONFIGFILE);
-                            if(File.Exists(configPath))
-                            {
-                                var configInterpreter = new XmlInterpreter(configPath);
-                                InitializeWith(new WindsorContainer(configInterpreter));   
-                            }else
-                            {
-                                InitializeWith(new WindsorContainer());
-                            }
-                        }
-
-                        Debug.WriteLine(string.Format("Trying to load windsor config from '{0}'", configPath));
-
-                        
-                        _initiliazed = true;
-                    }
-                }
-            }
-        }
-
-        public static void InitializeWith(IWindsorContainer container)
-        {
-            _container = container;
-            _initiliazed = true;
-        }
-
-        public static T Resolve<T>()
-        {
-            EnsureInitialized();
-            return _container.Resolve<T>();
-        }
-
-        public static T Resolve<T>(string key)
-        {
-            EnsureInitialized();
-            return _container.Resolve<T>(key);
-        }
-
-        public static IWindsorContainer GetContainer()
-        {
-            EnsureInitialized();
-            return _container;
-        }
-
-        public static void Reset()
-        {
-            if (_container != null)
-            {
-                _container.Dispose();
-                _container = null;
-            }
-        }
-
-        /// <summary>
-        /// Register controllers with DI container
-        /// </summary>
-        public static void RegisterControllersInContainer(Assembly assembly)
-        {
-            EnsureInitialized();
-
-            //add all controllers
-            foreach (var type in assembly.GetTypes())
-            {
-                if (!(typeof(IController).IsAssignableFrom(type) && type.IsClass)) continue;
-                var typekey = type.FullName.ToLowerInvariant();
-                Debug.WriteLine(string.Format("Registering controller '{0}' in container with key '{1}'", type.Name, typekey));
-                Register(typekey, type, LifestyleType.Transient);
-            }
-        }
-
-        /// <summary>
-        /// Registers all the types in the servicesNamespace that can be found in the assembly.
-        /// The first interface, in the form I[Service type name] found is used.
-        /// </summary>
-        /// <param name="assembly"></param>
-        /// <param name="servicesNamespace"></param>
-        public static void AutoRegisterTypesInContainer(Assembly assembly, string servicesNamespace)
-        {
-            AutoRegisterTypesInContainer(assembly, servicesNamespace, false);
-        }
-        public static void AutoRegisterTypesInContainer(Assembly assembly, string servicesNamespace, bool registerServiceIfNoInterface)
-        {
-            // Windsor mass component registration
-            EnsureInitialized();
-
-            //add all controllers
-            foreach (var type in assembly.GetTypes())
-            {
-                // If type is of registerType
-                if (type.IsClass && (string.IsNullOrEmpty(servicesNamespace)
-                                     || (type.Namespace != null && type.Namespace.StartsWith(servicesNamespace))))
-                {
-                    var typekey = type.FullName.ToLowerInvariant();
-
-                    // Look for an interface with the I[Type name]
-                    var typeName = type.Name;
-                    var firstInterface = type.GetInterfaces().FirstOrDefault(intface => intface.Name.Contains(typeName));
-                    if (firstInterface != null)
-                    {
-                        Register(typekey, firstInterface, type, LifestyleType.Transient);
-                    }
-                    else if (registerServiceIfNoInterface)
-                    {
-                        Register(typekey, type, LifestyleType.Transient);
-                    }
-
-                    Debug.WriteLine(string.Format("Registering '{0}' in container with key '{1}' as it is in '{2}'", type.Name, typekey, servicesNamespace));
-                }
-            }
-        }
-
-        public static void Register(Type classType, LifestyleType lifestyleType)
-        {
-            EnsureInitialized();
-
-            var typekey = classType.FullName.ToLowerInvariant();
-            _container.AddComponentLifeStyle(typekey, classType, lifestyleType);
-        }
-        public static void Register(string typeKey, Type classType, LifestyleType lifestyleType)
-        {
-            EnsureInitialized();
-            _container.AddComponentLifeStyle(typeKey, classType, lifestyleType);
-        }
-        public static void Register(string typeKey, Type serviceType, Type classType, LifestyleType lifestyleType)
-        {
-            EnsureInitialized();
-            _container.AddComponentLifeStyle(typeKey, serviceType, classType, lifestyleType);
-        }
-        public static Boolean Remove(string typeKey)
-        {
-            EnsureInitialized();
-
-            return _container.Kernel.RemoveComponent(typeKey);
-        }
-    }
-}

DependencyInjection/WebApp/Models/ProductEditModel.cs

-using System.Collections.Generic;
-using System.ComponentModel;
+using System.ComponentModel;
 using System.ComponentModel.DataAnnotations;
 using System.Web.Mvc;
 

DependencyInjection/WebApp/Models/ProductShowModel.cs

         [DisplayName("Beskrivelse")]
         public string Description { get; set; }
 
-        [DisplayName("ProduktNo")]
+        [DisplayName("Varenr")]
         public string ProductNumber { get; set; }
 
         [DisplayName("Kategori")]
         public string CategoryName { get; set; }
+
         public ProductListModel[] RelatedProducts { get; set; }
     }
 }

DependencyInjection/WebApp/Views/Product/List.aspx

 <%foreach(var p in Model){%>
     <%=Html.DisplayFor(x=>p) %>
 <%} %>
-        <div style="text-align:right"><%=Html.ActionLink("Opret produkt","Create","Product") %></div>
+
+<div style="text-align:right"><%=Html.ActionLink("Opret produkt","Create","Product") %></div>
 
 </asp:Content>

DependencyInjection/WebApp/WebApp.csproj

     <Compile Include="Global.asax.cs">
       <DependentUpon>Global.asax</DependentUpon>
     </Compile>
-    <Compile Include="IoC.cs" />
+    <Compile Include="Helpers\IoC.cs" />
     <Compile Include="Models\ProductListModel.cs" />
     <Compile Include="Models\ProductShowModel.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     </ProjectReference>
   </ItemGroup>
   <ItemGroup>
-    <Content Include="Log4Net.config" />
-  </ItemGroup>
-  <ItemGroup>
     <Content Include="Views\Shared\Default.Master" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />