Last active
July 20, 2017 09:43
-
-
Save sakapon/54ef60b0d084e0f259a973fc119f5425 to your computer and use it in GitHub Desktop.
ProxySample/CrossCuttingConsole/NorthwindBusiness
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.Transactions; | |
namespace CrossCuttingConsole | |
{ | |
public class NorthwindBusiness : MarshalByRefObject | |
{ | |
[TraceLog] | |
[TransactionScope] | |
public short SelectUnitsInStock() | |
{ | |
Console.WriteLine("SelectUnitsInStock"); | |
// cf. https://sakapon.wordpress.com/2011/10/02/dirtyread2/ | |
using (var context = new NorthwindEntities()) | |
{ | |
var product = context.Products.Single(p => p.ProductID == 1); | |
return product.UnitsInStock; | |
} | |
} | |
[TraceLog] | |
[TransactionScope(IsolationLevel.Serializable)] | |
public void InsertCategory(string name) | |
{ | |
Console.WriteLine("InsertCategory"); | |
// cf. https://sakapon.wordpress.com/2011/12/14/phantomread2/ | |
using (var context = new NorthwindEntities()) | |
{ | |
context.AddToCategories(Category.CreateCategory(0, name)); | |
context.SaveChanges(); | |
} | |
} | |
public int PropertyTest { get; [TraceLog]set; } | |
[TraceLog] | |
public void ErrorTest() | |
{ | |
throw new InvalidOperationException("This is an error test."); | |
} | |
} | |
} |
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; | |
namespace CrossCuttingConsole | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var nw = CrossCuttingProxy.CreateProxy<NorthwindBusiness>(); | |
var units = nw.SelectUnitsInStock(); | |
nw.InsertCategory("Books"); | |
nw.PropertyTest = 123; | |
try | |
{ | |
nw.ErrorTest(); | |
} | |
catch (Exception) | |
{ | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment