Skip to content

Commit

Permalink
spell check
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Jun 24, 2024
1 parent c179b3b commit 1e4228c
Show file tree
Hide file tree
Showing 7 changed files with 477 additions and 1 deletion.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"NETSTANDARD",
"Newobj",
"overriden",
"pfid",
"rebalance",
"Serilog",
"Statefully",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-t4": {
"version": "2.3.1",
"commands": [
"t4"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma warning disable 1591

namespace Example
{
public interface IService { }

public class MyService : IService
{
public MyService(IDependencyA a, DependencyB<string> b, RuntimeDependencyC c) { }
}

public interface IDependencyA { }

public class DependencyA : IDependencyA { }

// let's make it struct for fun
public struct DependencyB<T>
{
public readonly IDependencyA A;
public DependencyB(IDependencyA a) => A = a;
}

public class RuntimeDependencyC
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<#
// TODO:
// 1. Fill-in method `GetContainerWithRegistrations` below with creation of DryIoc `Container` and registrations.
// 2. Specify the resolution roots via `SpecifyResolutionRoots` method, see example below.
// 3. Save the "Container.Generated.tt" file. Confirm the Visual Studio prompt if any.
// 4. Check the "Container.Generated.cs" for the generated results and issues.
//
// Note:
// - When specifying assembly path, you may use $(SolutionDir), $(ProjectDir), $(Configuration) parameters.
//
#>
<#@ import Namespace="DryIoc" #>
<#@ import Namespace="DryIoc.ImTools" #>
<#// TODO: Insert the assemblies and namespaces of your services to be registered in container #>
<#@ import Namespace="Example" #>
<#+
// TODO: Specify the container and registrations ...
IContainer GetContainerWithRegistrations()
{
var container = new Container();

// TODO: Register compile-time resolved services using the same DryIoc API
// or move part (or all) of the existing registrations here from your current DI configuration.

// These are example registrations to build the IService resolution root and its dependencies
container.Register<IService, MyService>();
container.Register<IDependencyA, DependencyA>();
container.Register(typeof(DependencyB<>), setup: Setup.With(asResolutionCall: true));

// Note that `RegisterDelegate`, `RegisterInstance` and `Use` methods are not supported because
// they using the run-time state.
// Instead you may use `RegisterPlaceholder` to put a hole in the generated object graph,
// then you fill it in with the run-time registration, e.g. `container.Register<RuntimeDependency>();`
container.RegisterPlaceholder<RuntimeDependencyC>();

// You may batch register assemblies as well
// container.RegisterMany(new[] { MyAssembly });

return container;
}

// TODO: For each passed registration specify what resolution roots it provides, null if none
ServiceInfo[] SpecifyResolutionRoots(ServiceRegistrationInfo reg) =>
reg.AsResolutionRoot ? reg.ToServiceInfo().One() : null;

// TODO: Specify the resolution roots explicitly
ServiceInfo[] CustomResolutionRoots =
{
ServiceInfo.Of<Example.IService>(),
};

// TODO: Specify the namespace to go into `using` instead of qualifying its types all the times
// You may generate the Container.Generated.cs first, then look what you want to move to `using`
string[] NamespaceUsings =
{
"Example",
//"Foo.Bar.Buzz",
};
#>
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// <auto-generated/>
/*
The MIT License (MIT)
Copyright (c) 2016-2022 Maksim Volkau
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
========================================================================================================
The code below is generated automatically at compile-time and changes to it will be lost on the next gen.
========================================================================================================
Generation is completed successfully.
--------------------------------------------------------------------------------------------------------
*/

using System;
using System.Collections.Generic;
using System.Threading;
using DryIoc.ImTools;

// Provided `NamespaceUsings`:
using Example;

namespace DryIoc
{
partial class Container
{
partial void HasCompileTimeGeneratedContainer(ref bool hasIt) => hasIt = true;

partial void ResolveGenerated(ref object service, Type serviceType)
{
if (serviceType == typeof(IService))
service = Get_IService_0(this);
}

partial void ResolveGenerated(ref object service,
Type serviceType, object serviceKey, Type requiredServiceType, Request preRequestParent, object[] args)
{
if (serviceType == typeof(DependencyB<string>))
{
if (serviceKey == null &&
requiredServiceType == null &&
Equals(preRequestParent, Request.Empty.Push(
typeof(IService),
20001,
typeof(MyService),
Reuse.Transient,
RequestFlags.IsResolutionCall|RequestFlags.DoNotPoolRequest)))
service = GetDependency_DependencyB_0(this);
}
}

partial void ResolveManyGenerated(ref IEnumerable<ResolveManyResult> services, Type serviceType)
{
services = ResolveManyGenerated(serviceType);
}

private IEnumerable<ResolveManyResult> ResolveManyGenerated(Type serviceType)
{
if (serviceType == typeof(IService))
yield return ResolveManyResult.Of(r => Get_IService_0(r));
}

internal static IService Get_IService_0(IResolverContext r) =>
new MyService(
new DependencyA(),
((DependencyB<string>)r.Resolve(
typeof(DependencyB<string>),
default(object),
IfUnresolved.Throw,
default(System.Type),
Request.Empty.Push(
typeof(IService),
20001,
typeof(MyService),
Reuse.Transient,
RequestFlags.IsResolutionCall|RequestFlags.StopRecursiveDependencyCheck|RequestFlags.DoNotPoolRequest),
default(object[]))),
((RuntimeDependencyC)r.Resolve(
typeof(RuntimeDependencyC),
default(object),
IfUnresolved.Throw,
default(System.Type),
Request.Empty.Push(
typeof(IService),
20001,
typeof(MyService),
Reuse.Transient,
RequestFlags.IsResolutionCall|RequestFlags.StopRecursiveDependencyCheck|RequestFlags.DoNotPoolRequest),
default(object[]))));

internal static DependencyB<string> GetDependency_DependencyB_0(IResolverContext r) =>
new DependencyB<string>(new DependencyA());

}
}
Loading

0 comments on commit 1e4228c

Please sign in to comment.