This file contains hidden or 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
void Main() | |
{ | |
ProxyGenerator proxyGenerator = CreateProxyGenerator(); | |
IService proxy = | |
proxyGenerator | |
.CreateInterfaceProxyWithTargetInterface(new Service() as IService, new TracingInterceptorAspect()); | |
proxy.ProcessRequest(); | |
This file contains hidden or 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
void Main() | |
{ | |
ProxyGenerator proxyGenerator = CreateProxyGenerator(); | |
IService proxy = | |
proxyGenerator | |
// http://kozmic.pl/2009/04/01/castle-dynamic-proxy-tutorial-part-ix-interface-proxy-with-target/ | |
.CreateInterfaceProxyWithTargetInterface(new Service() as IService, new TracingInterceptorAspect()); | |
proxy.ProcessRequest(); |
This file contains hidden or 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
void Main() | |
{ | |
// nunit runner | |
NUnit.ConsoleRunner.Runner.Main(new string[] | |
{ | |
Assembly.GetExecutingAssembly().Location, | |
}); | |
} | |
public class ClassUnderTest |
This file contains hidden or 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
void Main() | |
{ | |
// create kernel with conventions | |
using(var kernel = InitializeKernel()) | |
{ | |
var backend = kernel.Get<IBackend>(); | |
Assert.That(backend, Is.Not.InstanceOfType(typeof(ProdBackend)) | |
.And.InstanceOfType(typeof(TestBackend))); | |
} |
This file contains hidden or 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
void Main() | |
{ | |
var kernel = new StandardKernel(); | |
kernel.Load<FuncModule>(); // for sake of LinqPAD | |
kernel.Bind<IDependencyFactory>().ToFactory(); | |
// wire concreet implementation of | |
kernel |
This file contains hidden or 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
void Main() | |
{ | |
using(var kernel = new StandardKernel(new CarModule())) | |
{ | |
kernel.Load<FuncModule>(); // for sake of LinqPAD | |
var factory = kernel.Get<ICarFactory>(); | |
Assert.That(factory, Is.Not.Null); | |
This file contains hidden or 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
// More about aspect life time | |
// http://www.sharpcrafters.com/blog/post/Day-10-Aspect-Lifetime-Scope-Part-2.aspx | |
[Serializable] | |
public class InjectionAspectWithCallbackAttribute : OnMethodBoundaryAspect, IInstanceScopedAspect | |
{ | |
private ILogger Logger { get; set; } | |
public static Func<ILogger> InjectLogger { get; set; } | |
#region OnMethodBoundaryAspect overrides |
This file contains hidden or 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
void Main() | |
{ | |
using(var kernel = new StandardKernel(new Module())) | |
{ | |
kernel.Load<FuncModule>(); // for sake of LinqPAD | |
var instance1 = kernel.Get<MyClass>(new ConstructorArgument("myArg", "test")); | |
var instance2 = kernel.Get<MyClass>(new ConstructorArgument("myArg", "test")); | |
Assert.That(instance1, Is.Not.Null.And.SameAs(instance2)); |
This file contains hidden or 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
void Main() | |
{ | |
var engine = new ScriptEngine(); | |
new[] | |
{ | |
typeof (Math).Assembly, | |
this.GetType().Assembly | |
}.ToList().ForEach(assembly => engine.AddReference(assembly)); | |
This file contains hidden or 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
void Main() | |
{ | |
var engine = new ScriptEngine(); | |
new[] | |
{ | |
typeof (Math).Assembly, | |
this.GetType().Assembly | |
}.ToList().ForEach(assembly => engine.AddReference(assembly)); | |