Skip to content

Commit

Permalink
Adding an AutoDesired type for use in cases where exception robustnes…
Browse files Browse the repository at this point in the history
…s is desired
  • Loading branch information
codemercenary committed Aug 2, 2014
1 parent 4ac4f37 commit c3b7e62
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions autowiring/Autowired.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,31 @@ class AutoRequired:
bool IsAutowired(void) const {return std::shared_ptr<T>::get() != nullptr;}
};

/// <summary>
/// Convenience class which attempts to inject type T and discards any exceptions
/// </summary>
/// <remarks>
/// Use of this type is functionally equivalent to the following:
///
/// try {
/// AutoCurrentContext()->Inject&lt;T&gt;();
/// catch(...) {}
/// Autowired&lt;T&gt; foo;
///
/// Users who wish to know whether an exception was thrown may replace uses of AutoDesired with the above
/// and perform their own handling.
/// </remarks>
template<class T>
class AutoDesired:
public Autowired<T>
{
public:
AutoDesired(void) {
try { AutoRequired<T>(); }
catch(...) {}
}
};

/// <summary>
/// Convenience class functionally identical to AutoRequired, but specialized to forward ctor arguments
/// </summary>
Expand Down

0 comments on commit c3b7e62

Please sign in to comment.