Skip to content

Commit

Permalink
Support of a simple factory with lambdas without explicit type defini…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
NikolayPianikov committed Dec 12, 2024
1 parent c970a01 commit 8498248
Show file tree
Hide file tree
Showing 108 changed files with 339 additions and 234 deletions.
2 changes: 1 addition & 1 deletion readme/ArrayDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ partial class Array
{
private readonly Array _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Array()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/EnumDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ partial class Enum
{
private readonly Enum _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Enum()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/FuncDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ partial class Func
{
private readonly Func _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Func()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/SingletonDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ partial class Singleton
private Service1? _scopedService141;
private Service4? _scopedService444;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Singleton()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/TransientDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ partial class Transient
{
private readonly Transient _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Transient()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/a-few-partial-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/accumulators.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ partial class Composition

private XyzDependency? _singletonXyzDependency45;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
26 changes: 11 additions & 15 deletions readme/advanced-interception.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,26 @@ This approach of interception maximizes performance by precompiling the proxy ob
```c#
public interface IDependency
{
void DependencyCall();
int DependencyRun();
}

class Dependency : IDependency
{
public void DependencyCall()
{
}
public int DependencyRun() => 33;
}

public interface IService
{
IDependency Dependency { get; }

void ServiceCall();
string ServiceRun();
}

class Service(IDependency dependency) : IService
{
public IDependency Dependency { get; } = dependency;

public void ServiceCall()
{
}
public string ServiceRun() => "Abc";
}

internal partial class Composition : IInterceptor
Expand Down Expand Up @@ -64,8 +60,8 @@ internal partial class Composition : IInterceptor

public void Intercept(IInvocation invocation)
{
_log.Add(invocation.Method.Name);
invocation.Proceed();
_log.Add($"{invocation.Method.Name} returns {invocation.ReturnValue}");
}

private static class ProxyFactory<T>
Expand Down Expand Up @@ -105,14 +101,14 @@ DI.Setup(nameof(Composition))
var log = new List<string>();
var composition = new Composition(log);
var service = composition.Root;
service.ServiceCall();
service.Dependency.DependencyCall();
service.ServiceRun();
service.Dependency.DependencyRun();

log.ShouldBe(
ImmutableArray.Create(
"ServiceCall",
"get_Dependency",
"DependencyCall"));
"ServiceRun returns Abc",
"get_Dependency returns Castle.Proxies.IDependencyProxy",
"DependencyRun returns 33"));
```

The following partial class will be generated:
Expand All @@ -122,7 +118,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/async-disposable-scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ partial class Composition: IDisposable, IAsyncDisposable

private Dependency? _scopedDependency43;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/async-disposable-singleton.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ partial class Composition: IDisposable, IAsyncDisposable

private Dependency? _singletonDependency43;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/async-enumerable.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/auto-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
11 changes: 4 additions & 7 deletions readme/auto-scoped.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ partial class Composition
// Session composition root
.Root<Service>("SessionRoot", kind: RootKinds.Private)
// Auto scoped
.Bind().To<IService>(ctx =>
.Bind().To(IService (Composition baseComposition) =>
{
// Injects a base composition
ctx.Inject(out Composition baseComposition);

// Creates a session
var session = new Composition(baseComposition);

// Provides a root
return session.SessionRoot;
})

Expand Down Expand Up @@ -77,7 +74,7 @@ partial class Composition

private Dependency? _scopedDependency43;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand All @@ -99,10 +96,10 @@ partial class Composition
{
Composition transientComposition3 = this;
IService transientIService2;
// Injects a base composition
Composition localBaseComposition81 = transientComposition3;
// Creates a session
var localSession82= new Composition(localBaseComposition81);
// Provides a root
transientIService2 = localSession82.SessionRoot;
IService localValue80 = transientIService2;
return localValue80;
Expand Down
2 changes: 1 addition & 1 deletion readme/bind-attribute-for-a-generic-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ partial class Composition

private Facade? _singletonFacade43;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/bind-attribute-with-lifetime-and-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ partial class Composition
private IDependency? _singletonIDependency0;
private Facade? _singletonFacade43;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/bind-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ partial class Composition

private Facade? _singletonFacade43;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/check-for-a-root.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/composition-root-kinds.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/composition-roots.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/custom-generic-argument-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/custom-generic-argument.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/decorator.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/default-lifetime-for-a-type-and-a-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ partial class Composition
private Dependency? _singletonDependency43;
private Dependency? _singletonDependency44;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/default-lifetime-for-a-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ partial class Composition

private Dependency? _singletonDependency43;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/default-lifetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ partial class Composition
private Service? _singletonService44;
private Dependency? _singletonDependency43;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/default-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
4 changes: 2 additions & 2 deletions readme/dependent-compositions.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down Expand Up @@ -196,7 +196,7 @@ partial class OtherComposition
{
private readonly OtherComposition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public OtherComposition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/disposable-singleton.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ partial class Composition: IDisposable

private Dependency? _singletonDependency43;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/enumerable-generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/enumerable.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ partial class Composition
{
private readonly Composition _root;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/exposed-generic-roots.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ partial class Composition

private Integration.CompositionWithGenericRootsInOtherProject? _singletonCompositionWithGenericRootsInOtherProject43;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/exposed-roots-with-tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ partial class Composition

private Integration.CompositionWithTagsInOtherProject? _singletonCompositionWithTagsInOtherProject43;

[OrdinalAttribute(20)]
[OrdinalAttribute(256)]
public Composition()
{
_root = this;
Expand Down
Loading

0 comments on commit 8498248

Please sign in to comment.