-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Mvc3StructureMapIoc | ||
{ | ||
public class ModelBinderTypeMappingDictionary : Dictionary<Type, Type> | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
using System; | ||
using System.Web.Mvc; | ||
using System.Web.Routing; | ||
using StructureMap; | ||
|
||
namespace Mvc3StructureMapIoc | ||
{ | ||
public class StructureMapControllerActivator : IControllerActivator | ||
{ | ||
public StructureMapControllerActivator(IContainer container) | ||
{ | ||
_container = container; | ||
} | ||
|
||
private IContainer _container; | ||
|
||
public IController Create(RequestContext requestContext, Type controllerType) | ||
{ | ||
return DependencyResolver.Current.GetService(controllerType) as IController; | ||
return _container.GetInstance(controllerType) as IController; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Web.Mvc; | ||
using StructureMap; | ||
|
||
namespace Mvc3StructureMapIoc | ||
{ | ||
public class StructureMapModelBinderProvider : IModelBinderProvider | ||
{ | ||
public StructureMapModelBinderProvider(IContainer container) | ||
{ | ||
_container = container; | ||
} | ||
|
||
private IContainer _container; | ||
|
||
public IModelBinder GetBinder(Type modelType) | ||
{ | ||
var typeMappings = _container.GetInstance<ModelBinderTypeMappingDictionary>(); | ||
if (typeMappings.ContainsKey(modelType)) | ||
return _container.GetInstance(typeMappings[modelType]) as IModelBinder; | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace SampleWebsite.Code | ||
{ | ||
public class AThing | ||
{ | ||
public string SomeRandomValue { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Web.Mvc; | ||
|
||
namespace SampleWebsite.Code | ||
{ | ||
public class AThingModelBinder : DefaultModelBinder | ||
{ | ||
public AThingModelBinder(IBar bar) | ||
{ | ||
_bar = bar; | ||
} | ||
|
||
private IBar _bar; | ||
|
||
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) | ||
{ | ||
return new AThing() | ||
{ | ||
SomeRandomValue = _bar.IPityTheFoo() | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@{ | ||
ViewBag.Title = "ModelBindAThing"; | ||
} | ||
|
||
<h2>Model Bind a Thing</h2> | ||
|
||
@ViewBag.Stuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters