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
using System; | |
using System.Reflection; | |
using PostSharp.Aspects; | |
using PostSharp.Extensibility; | |
using NUnit.Framework; | |
namespace Examples | |
{ | |
public interface IServiceWithDependency | |
{ |
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
void Main() | |
{ | |
JsonConvert.DeserializeObject<Root>(testJson).Dump(); | |
} | |
readonly string testJson = | |
"{\"Profile\": [{" + | |
" \"Name\":\"Joe\"," + | |
" \"Last\":\"Doe\"," + | |
" \"Client\":" + |
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
SQLiteConnection connection = boundSession.GetConnection(); | |
using (var cmd = new SQLiteCommand("PRAGMA foreign_keys = OFF", connection)) | |
{ | |
cmd.ExecuteNonQuery(); | |
} | |
var sqlLiteUnitTest = new SqlLiteDbUnitTest(connection); | |
sqlLiteUnitTest.ReadXmlSchema(xsdFile); |
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
[Serializable] | |
public class TracingAspectAttribute : OnMethodBoundaryAspect | |
{ | |
// Question #1: Is there any better way to design aspect | |
// and to inject dependency into it? | |
public Type AbstractFactoryType { get; set; } | |
private ILogger Logger { get; set; } | |
// Compile time validation. | |
// Question #2: Better approach to ensure during post-compile time |
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
void Main() | |
{ | |
// 4 from your Compositon Root ... | |
using(var kernel = InitializeKernel()) | |
{ | |
// 4.1 resolve delivery services by names | |
var upsWorldShip = kernel.Get<IShippingCompanyService>("ShippingUpsWorldShip"); | |
var fedExDesktopApps = kernel.Get<IShippingCompanyService>("ShippingFedExDesktopApps"); | |
// 4.2 delivery processing |
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
void Main() | |
{ | |
// create kernel with conventions | |
using(var kernel = InitializeKernel()) | |
{ | |
// ninject.extensions.conventions would not automaticaly select wich of | |
// two implementations of IDependency to resolve | |
var dependency = kernel.Get<IDependency>(); | |
Assert.That(dependency, |
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
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 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 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 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 |