Skip to content

Instantly share code, notes, and snippets.

View kkozmic's full-sized avatar
🎯
Focusing

Krzysztof Kozmic kkozmic

🎯
Focusing
View GitHub Profile
// class like this
public class Something
{
public string Name{get;set;}
public string Zip {get;set;}
public string Street {get;set;}
}
// maps to json like this
// this...
<a href="@Model.GithubAddHookUrl" target="_blank" class="btn small">Go to Github</a>
// ...or this ...
@Html.ButtonLink(Model.GithubAddHookUrl, "Go to Github")
// ...or perhaps this? (via extension method)
@Model.GithubAddHookUrl.ButtonLink("Go to Github")
public interface IFoo<T>
{}
public class SimpleFoo<T>: IFoo<T>
{}
public class StructOnlyFoo<T>: IFoo<T> where T : struct
{}
public class FooWithBar<T>:IFoo<T>
var query = from foo in session.Query<Foo>()
from bar in foo.Something.Bars
select anythingReally;
// LINQ provider throws exception complaining
// about second 'from', but in reality it complains about the 'Something' between foo and Bars
var result = query.ToList();
var fooMock = new Mock<IFoo>().Object;
fooMock.Bar = "bar";
Debug.Assert(fooMock.Bar == "bar");
// full doco for fluent API here: http://docs.castleproject.org/Windsor.Registering-components-by-conventions.ashx
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<IPocessor>()
.ImplementedBy<SomeProcessor>()
.Named("processor") // do you really request this by name? If no you don't need to set the name
.ServiceOverrides(
ServiceOverride.ForKey("repositoryB")
.Eq("CastleInstallersInv.Repository.RepositoryB")));
/* this gets executed */
SELECT this_.Id as Id0_0_,
this_.Author as Author0_0_,
this_.Title as Title0_0_,
this_1_.Comment as Comment1_0_,
this_1_.LanguageId as LanguageId1_0_
FROM [Blog] this_
inner join Comment this_1_
on this_.Id = this_1_.Blog_id
WHERE (this_.LanguageId = 2 /* @p0 */)
@kkozmic
kkozmic / gist:863736
Created March 10, 2011 08:10
Scoped lifestyle in Windsor
[Test]
public void Implicitly_graph_scoped_component_instances_are_reused()
{
Container.Register(
Component.For<A>().LifeStyle.ScopedPer<CBA>(),
Component.For<B>().LifeStyle.Transient,
Component.For<CBA>().LifeStyle.Transient);
var cba = Container.Resolve<CBA>();
Assert.AreSame(cba.A, cba.B.A);
public class TransientScopedInWebRequestLifestyleModule : IHttpModule
{
// Fields
private const string key = "trolls_and_goblins";
public static IKernel kernel;
// Methods
public void Dispose()
{
//in a per-web-request class
IKernel kernel;
List<object> tracked;
public object GetMeDaObject()
{
var obj = kernel.Resolve<DaObject>();
if(kernel.ReleasePolicy.HasTrack(obj))
{