-
Notifications
You must be signed in to change notification settings - Fork 46
/
ideas.txt
133 lines (111 loc) · 3.61 KB
/
ideas.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
c'tor(ITransactionManager manager)
[Transaction]
public void A()
{
// access transaction through:
//_manager.CurrentTransaction.Value
}
[Transaction]
public void B()
{
// upgrade current transaction to file transaction, causes LTM to be resource manager.
_Manager.CurrentTransaction.Value
.UpgradeToFileTransaction() : IFileSystem
// so:
_Manager.CurrentTransaction.Value // : ITransaction
.UpgradeToFileTransaction() // Castle.Transactions.IO.Extensions.UpgradeToFileTransaction(this ITransaction t)
.GetDirectory("/usr/xyz/abc") // interface method in IFileSystem
.SelectMany(d => d.Ls()) // Ls extension method on IDirectory
.Run(Console.WriteLine); // Interactive Extensions' extension method on IEnumerable<T>
}
class Cc {
c'tor(Func<IFileSystem> fsFactory)
// causes KTM to be resource manager
[FileTransaction] // in Castle.Transactions.IO, class FileTransactionAttribute : TransactionAttribute
public void C()
{
// in FileTxFacility:
// Component.For<IFileSystem>
// .ImplementedBy<TxFileSystem>()
// .Lifestyle.PerTopTranscation()
_fsFactory() // : IFileSystem (conretely: TxFileSystem)
.GetDirectory("\\?\F:\\a\\b\\c")
.GetFile("d.txt")
. etc
}
}
// for reference
namespace System.Reactive {
public interface IObservable<out T> {
}
}
// registering observables for transactions:
class NHibernateFacility : AbstractFacility {
void Init(IKernel k) {
k.Register(Component.For<ISession>()
.UsingFactoryMethod((k,c) => ...)
.Lifestyle.PerTopTransaction(
// observable for top transaction,
// don't care; FlushMode.Auto takes care of it through System.Transaction.Current's CompletedTransaction evt.
null,
// observable for dependent transaction
(obs : IObservable<ISession>) => obs
.Subscribe(
s => s.Flush(),
ex => _logger.Warn("couldn't complete tx", ex),
() => _logger.Debug(() => "Completed transaction))
)
);
}
}
// registering read-only ISession:
Component.For<ISession>()
// ...
.PerTopTransaction(
namespace Castle.Facilities.AutoTx {
public static class Extensions {
public ComponentRegistration<TS> PerTransaction(this ComponentRegistration<TS> reg) {
// ...
}
public ComponentRegistration<TS> PerTopTransaction(this ComponentRegistration<TS> reg) {
// ...
}
}
}
namespace Castle.Transactions.IO {
public static class Extensions {
public ComponentRegistration<TS> PerTransaction(this ComponentRegistration<TS> reg,
Action<IObservable<TS>> transactionEvents) {
// ...
}
public ComponentRegistration<TS> PerTopTransaction(this ComponentRegistration<TS> reg,
Action<IObservable<TS>> topTransactionEvents,
Action<IObservable<TS>> dependentTransactionEvents) {
}
}
}
namespace Castle.IO { // merged from openfilesystem
public interface IFileSystem {
IDirectory GetDirectory(string directoryPath);
IDirectory GetDirectory(Path directoryPath);
Path GetPath(string path);
ITemporaryDirectory CreateTempDirectory();
IDirectory CreateDirectory(string path);
IDirectory CreateDirectory(Path path);
IFile GetFile(string itemSpec);
ITemporaryFile CreateTempFile();
IDirectory GetTempDirectory();
IDirectory GetCurrentDirectory();
}
}
// assembly: Castle.IO.Fluent
namespace Castle.IO {
public static class Extensions {
// everything from FluentPath here
public static IEnumerable<IDirectory> ForEach(Action<IDirectory> a) {
// ... etc
}
// move
// delete etc
}
}