-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InitializeAsync MUST not require interface impl #32
Comments
I think I would like to do this at some point, but it's not highest priority for me. Hopefully I'll make a product roadmap soon so people can see what I plan to work on and in which order. |
What I think I will do is as follows: In the This means you can do this: public class A
{
public void SetUp(){}
}
[Register(typeof(A), initializeMethod: nameof(A.SetUp))]
public class Container : IContainer<A>{} I will keep the |
The following is a possible solution which can be used without adding any new features: Define your own interface e..g public interface INeedsInitialization
{
/// Must be safe to call multiple times
public ValueTask InitializeAsync();
}
public class InitializationModule
{
[DecoratorFactory] public static async ValueTask<T> InitializeAsync(T t) where T : INeedsInitialization
{
await t.InitializeAsync();
return t;
}
} Then if you import that module, you can automatically initialize anything that implements that interface. If there's any type which you don't control and need to initialize you can make a custom decorator specifically for it: public class SomeClass
{
public ValueTask PrepareAsync();
}
[Register(typeof(SomeClass))]
public class SomeClassModule
{
[DecoratorFactory] public static async ValueTask<SomeClass> InitializeAsync(SomeClass someClass)
{
await someClass.PrepareAsync();
return someClass;
}
} This also allows you to do much more complex initialization of a type if necessary, but adds a bit of boilerplate. Would you consider this sufficient? |
Just do structural stuff.
The text was updated successfully, but these errors were encountered: