Skip to content

Commit

Permalink
refactor of consumption peasy 2.0 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Hanusa committed Jun 24, 2017
1 parent 8675366 commit 47c199b
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 18 deletions.
1 change: 1 addition & 0 deletions Orders.com.WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
//ConfigureInMemoryUsage();
ConfigureHttpClientUsage();
//ConfigureEFUsage();
}

private void ConfigureHttpClientUsage()
Expand Down
2 changes: 2 additions & 0 deletions Orders.com.Web.MVC/App_Start/NinjectWebCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ private static void RegisterServices(IKernel kernel)
if (binding.AsSingleton) ninjectBinding.InSingletonScope();
foreach (var defaultProp in binding.DefaultProperties)
ninjectBinding.WithPropertyValue(defaultProp.PropertyName, Cast(defaultProp.Value, defaultProp.Type));
foreach (var constructorArg in binding.ConstructorArguments)
ninjectBinding.WithConstructorArgument(constructorArg.ArgumentName, constructorArg.Value);
}
catch
{
Expand Down
7 changes: 7 additions & 0 deletions Orders.com.Web.MVC/Configuration/DIConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public DIDefaultPropConfigList DefaultProperties
get { return (DIDefaultPropConfigList)base["defaultProperties"]; }
set { base["defaultProperties"] = value; }
}

[ConfigurationProperty("constructorArguments")]
public DIConstructorArgConfigList ConstructorArguments
{
get { return (DIConstructorArgConfigList)base["constructorArguments"]; }
set { base["constructorArguments"] = value; }
}

[ConfigurationProperty("asSingleton")]
public bool AsSingleton
Expand Down
28 changes: 28 additions & 0 deletions Orders.com.Web.MVC/Configuration/DIConstructorArgConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Configuration;

namespace Orders.com.Web.MVC.Configuration
{
public class DIConstructorArgConfig : ConfigurationElement
{
[ConfigurationProperty("argumentName")]
public string ArgumentName
{
get { return (string)base["argumentName"]; }
set { base["argumentName"] = value; }
}

[ConfigurationProperty("value")]
public string Value
{
get { return (string)base["value"]; }
set { base["value"] = value; }
}

[ConfigurationProperty("type")]
public string Type
{
get { return (string)base["type"]; }
set { base["type"] = value; }
}
}
}
62 changes: 62 additions & 0 deletions Orders.com.Web.MVC/Configuration/DIConstructorArgConfigList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Collections.Generic;
using System.Configuration;

namespace Orders.com.Web.MVC.Configuration
{
[ConfigurationCollection(typeof(DIConstructorArgConfig))]
public class DIConstructorArgConfigList : ConfigurationElementCollection, IEnumerable<DIConstructorArgConfig>
{
/// <summary>
/// Gets the <see cref="DIConstructorArgConfig"/> configuration element at the specified index.
/// </summary>
/// <returns>The specified <see cref="DIConstructorArgConfig"/> configuration element.</returns>
/// <param name="index">The index to retrieve.</param>
public DIConstructorArgConfig this[int index]
{
get { return (DIConstructorArgConfig)BaseGet(index); }
}

/// <summary>
/// Adds the specified entry.
/// </summary>
/// <param name="entry">The entry.</param>
public void Add(DIConstructorArgConfig entry)
{
this.BaseAdd(entry);
}

/// <summary>
/// Creates a new <see cref="DIConstructorArgConfig"/>.
/// </summary>
/// <returns>
/// A new <see cref="DIConstructorArgConfig"/>.
/// </returns>
protected override ConfigurationElement CreateNewElement()
{
return new DIConstructorArgConfig();
}

/// <summary>
/// Gets the element key for a specified configuration element.
/// </summary>
/// <param name="element">The <see cref="FileDestinationConfig"/> to return the key for.</param>
/// <returns>
/// An <see cref="T:System.String"/> that acts as the key for the specified <see cref="FileDestinationConfig"/>.
/// </returns>
protected override object GetElementKey(ConfigurationElement element)
{
return ((DIConstructorArgConfig)element).ArgumentName;
}

public IEnumerable<DIConstructorArgConfig> GetAll()
{
for (int i = 0; i < this.Count; i++)
yield return this[i];
}

public new IEnumerator<DIConstructorArgConfig> GetEnumerator()
{
return GetAll().GetEnumerator();
}
}
}
36 changes: 18 additions & 18 deletions Orders.com.Web.MVC/DependencyInjection.config
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,34 @@

<!-- HTTP Data Proxies -->
<add fromType="Orders.com.BLL.DataProxy.ICategoryDataProxy, Orders.com.BLL" toType="Orders.com.DAL.Http.CategoriesHttpServiceProxy, Orders.com.DAL.Http">
<defaultProperties>
<add propertyName="baseAddress" value="https://localhost:53534/api/" type="System.String" />
</defaultProperties>
<constructorArguments>
<add argumentName="baseAddress" value="https://localhost:53534/api/" type="System.String" />
</constructorArguments>
</add>
<add fromType="Orders.com.BLL.DataProxy.IOrderItemDataProxy, Orders.com.BLL" toType="Orders.com.DAL.Http.OrderItemsHttpServiceProxy, Orders.com.DAL.Http">
<defaultProperties>
<add propertyName="baseAddress" value="https://localhost:53534/api/" type="System.String" />
</defaultProperties>
<constructorArguments>
<add argumentName="baseAddress" value="https://localhost:53534/api/" type="System.String" />
</constructorArguments>
</add>
<add fromType="Orders.com.BLL.DataProxy.IProductDataProxy, Orders.com.BLL" toType="Orders.com.DAL.Http.ProductsHttpServiceProxy, Orders.com.DAL.Http">
<defaultProperties>
<add propertyName="baseAddress" value="https://localhost:53534/api/" type="System.String" />
</defaultProperties>
<constructorArguments>
<add argumentName="baseAddress" value="https://localhost:53534/api/" type="System.String" />
</constructorArguments>
</add>
<add fromType="Orders.com.BLL.DataProxy.IInventoryItemDataProxy, Orders.com.BLL" toType="Orders.com.DAL.Http.InventoryItemsHttpServiceProxy, Orders.com.DAL.Http">
<defaultProperties>
<add propertyName="baseAddress" value="https://localhost:53534/api/" type="System.String" />
</defaultProperties>
<constructorArguments>
<add argumentName="baseAddress" value="https://localhost:53534/api/" type="System.String" />
</constructorArguments>
</add>
<add fromType="Orders.com.BLL.DataProxy.IOrderDataProxy, Orders.com.BLL" toType="Orders.com.DAL.Http.OrdersHttpServiceProxy, Orders.com.DAL.Http">
<defaultProperties>
<add propertyName="baseAddress" value="https://localhost:53534/api/" type="System.String" />
</defaultProperties>
<constructorArguments>
<add argumentName="baseAddress" value="https://localhost:53534/api/" type="System.String" />
</constructorArguments>
</add>
<add fromType="Orders.com.BLL.DataProxy.ICustomerDataProxy, Orders.com.BLL" toType="Orders.com.DAL.Http.CustomersHttpServiceProxy, Orders.com.DAL.Http">
<defaultProperties>
<add propertyName="baseAddress" value="https://localhost:53534/api/" type="System.String" />
</defaultProperties>
<constructorArguments>
<add argumentName="baseAddress" value="https://localhost:53534/api/" type="System.String" />
</constructorArguments>
</add>

<!-- In Memory Data Proxies -->
Expand Down
2 changes: 2 additions & 0 deletions Orders.com.Web.MVC/Orders.com.Web.MVC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@
<Compile Include="Configuration\DIConfig.cs" />
<Compile Include="Configuration\DIConfigList.cs" />
<Compile Include="Configuration\DIConfigSection.cs" />
<Compile Include="Configuration\DIConstructorArgConfig.cs" />
<Compile Include="Configuration\DIDefaultPropConfig.cs" />
<Compile Include="Configuration\DIConstructorArgConfigList.cs" />
<Compile Include="Configuration\DIDefaultPropConfigList.cs" />
<Compile Include="Controllers\AccountController.cs" />
<Compile Include="Controllers\CategoriesController.cs" />
Expand Down

0 comments on commit 47c199b

Please sign in to comment.