Comments (4)
I see. I wouldn't implement this myself, but if you send a PR I'd be happy to review.
from stronginject.
I don't see a problem with this, and I think it should be fairly simple to implement - we just add the interface to Owned<T>
, and add a check to InstanceSourcesScope
to return a ForwardedInstanceSource
wrapping and OwnedSource
if it sees IOwned
.
My only issue is I'm not convinced of the utility. This seems like a relatively niche use case, and there's a valid workaround.
I can see a separate advantage in that it allows other libraries to provide their own implementation of IOwned
, but in practice I can't really see that happening - Owned
takes a delegate in it's constructor so is pretty flexible.
from stronginject.
The biggest reason I would like this is that I recently had to add 110 occurrences of .AsObject()
into a project when moving from my own Owned type to using the one in the StrongInject library. I could mitigate this in a minority of the cases by making all the windowing system methods generic so they can directly take Owned<T>
without the caller having to create a new Owned<object>
themselves.
Hopefully it's not too hard to see why a windowing system deals heavily with Owned<object>
rather than Owned<AbcView>
and Owned<DefView>
, and why menu items have Func<Owned<object>>
properties. But obtaining these Owned<object>
instances has to start with StrongInject returning Owned<AbcView>
and Owned<DefView>
from injected delegates. I don't see a way around the .AsObject()
call syntax bloat without going back to the bad old days of having the windowing system dispose both views and view models by calling container.Release
directly rather than disposing an Owned<object>
. StrongInject doesn't provide such a method, so the mere ability to use StrongInject is the driver behind all of this.
Example of the syntax bloat imposed on callers since there's no implicit conversion from what the caller must have (Lease<SpecificViewModel>
) and what the navigation service must deal with (Lease<object>
):
navigationService.AddSiblingViewModel(this, baseFormulasViewModelFactory.Invoke(EditList.FocusedItem).AsObject());
from stronginject.
@YairHalberstadt As I'm working with the XML docs, I noticed that it looks like <para>
blocks may have been intended:
With <para>
:
I'm going ahead and making this change before basing IOwned<T>
docs off of them, but just give a shout if that's not what you would have wanted.
from stronginject.
Related Issues (20)
- Inject Func<Owned<T>> parameters HOT 1
- [Feature/Idea] Support for primary constructor generator HOT 2
- Innermost hasAwaitStarted catch block is a no-op and could be omitted HOT 3
- Update xamarin sample to maui
- 'registerAs' parameter for FactoryAttribute HOT 9
- Convenience methods for creating Owned<T> instances HOT 3
- Permitting null instead of empty delegate for Owned<T> and AsyncOwned<T> HOT 2
- Add diagnostic if any registered method return types are by ref.
- Circular dependency check is too restrictive for delegates HOT 23
- SI1103 warning location forces suppression to be all or nothing HOT 6
- Separate Microsoft DI from Asp.Net Core HOT 2
- Convert to IIncrementalGenerator HOT 18
- Retrieving design-time info about registrations HOT 5
- StrongInject Source Generator API HOT 1
- Confusing use of the term 'delegate parameters' in the readme HOT 2
- Support decorator factories that aren't gratuitously generic HOT 4
- Misleading info in README HOT 2
- Generic interface registration HOT 1
- asp.net middleware support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stronginject.