spring.net

How to wire events with methods using Autofac?

六眼飞鱼酱① 提交于 2019-11-29 07:11:37
Is it possible to wire events to methods with Autofac instead of whole object via interfaces/classes (through constructor and property injection). I want to bind at function level instead of type level. Programmatically I expect the following job to be done (in C#): someType.Output += someOtherType.Input; For example Spring.net does support the following construct to achieve that: <object id="SomeType" type="Whatever.SomeType, Whatever" /> <object id="SomeOtherType" type="Whatever.SomeOtherType, Whatever"> <listener event="Output" method="Input"> <ref object="SomeType" /> </listener> </object>

possible GetObjectsOfType replacement

血红的双手。 提交于 2019-11-28 14:24:09
I have this small piece of code var idObjects = Spring.Context.Support.ContextRegistry.GetContext() .GetObjectsOfType(typeof (ICustomInterfaceThatDoesSomething)); foreach (ICustomInterfaceThatDoesSomething icitds in idObjects.Values) icitds.DoSomething(); Is there a way i can avoid this by having spring.net automatically inject the singletons to a property i declare, like an array of ICustomInterfaceThatDoesSomething ? The only reason i want something like this is because i want to kill the .dll dependency on the project and this is the single point of usage. You could also use method

Unobtrusive AOP with Spring.Net

99封情书 提交于 2019-11-28 12:42:54
I'm trying to add logging to methods decorated with an attribute using Spring.Net for AOP . Step 1: Reference 'Spring.Core', 'Spring.Aop', 'Common.Logging' Step 2: Create an advice: using AopAlliance.Intercept; namespace MyApp.Aspects { public class LoggingAdvice : IMethodInterceptor { public object Invoke(IMethodInvocation invocation) { //todo: log started object rval = invocation.Proceed(); return rval; //todo: log finished } } } Step 3: Create an attribute: using System; namespace MyApp.Aspects { public class LoggingAttribute : Attribute { } } Step 4: Edit web.config <configuration>

Spring.Net without configuring it in app.config

无人久伴 提交于 2019-11-28 11:52:02
问题 Is there way to configure the objects from inside the code rather than configuring it in xml or app.config file. 回答1: On the spring.net homepage, you'll find an announcement for the CodeConfig project. CodeConfig allows you to create spring configuration from code, like for instance: [Configuration] public class MovieFinderConfiguration { [Definition] public virtual MovieLister MyMovieLister() { MovieLister movieLister = new MovieLister(); movieLister.MovieFinder = FileBasedMovieFinder();

Spring.NET.AOP - ExceptionHandlerAdvice doesnt replace custom exception

走远了吗. 提交于 2019-11-28 08:45:28
问题 this is my first and also I am beginner in Spring.NET and also AOP. I would like use Aspect for Exception Hadling for replacing, wrap and modify my custom exceptions. First I defined some entity and DAO. From method Save in DAO I will throw my exception. FYI: This is silly sample Entity: namespace ExceptionHandlingTutorial.Entities { public class Customer { public long Id { get; set; } public string Name { get; set; } } } DAO: namespace ExceptionHandlingTutorial.Dao { public interface

Configure an Envers RevisionListener via DI

喜你入骨 提交于 2019-11-28 05:19:57
问题 To add an audit trail to our application we decided to use NHibernate.Envers. To allow app specific tracking of revisions, the DefaultRevisionEntity was extended with user specific data. public virtual void NewRevision( object revisionEntity ) { var revisionData = revisionEntity as Revision; if( revisionData != null ) { // Set additional audit data. var identity = UserAccessor.CurrentIdentity; revisionData.UserId = identity.UserId; revisionData.EmployeeId = identity.EmployeeId; revisionData

Reflection says that interface method are virtual in the implemented type, when they aren't?

落花浮王杯 提交于 2019-11-28 03:13:07
问题 I have the following code in an unit test public bool TestMethodsOf<T, I>() { var impl = typeof(T); var valid = true; foreach (var iface in impl.GetInterfaces().Where(i => typeof(I).IsAssignableFrom(i))) { var members = iface.GetMethods(); foreach (var member in members) { Trace.Write("Checking if method " + iface.Name + "." + member.Name + " is virtual..."); var implMember = impl.GetMethod(member.Name, member.GetParameters().Select(c => c.ParameterType).ToArray()); if (!implMember.IsVirtual)

How to wire events with methods using Autofac?

有些话、适合烂在心里 提交于 2019-11-28 00:52:49
问题 Is it possible to wire events to methods with Autofac instead of whole object via interfaces/classes (through constructor and property injection). I want to bind at function level instead of type level. Programmatically I expect the following job to be done (in C#): someType.Output += someOtherType.Input; For example Spring.net does support the following construct to achieve that: <object id="SomeType" type="Whatever.SomeType, Whatever" /> <object id="SomeOtherType" type="Whatever

possible GetObjectsOfType replacement

此生再无相见时 提交于 2019-11-27 19:38:03
问题 I have this small piece of code var idObjects = Spring.Context.Support.ContextRegistry.GetContext() .GetObjectsOfType(typeof (ICustomInterfaceThatDoesSomething)); foreach (ICustomInterfaceThatDoesSomething icitds in idObjects.Values) icitds.DoSomething(); Is there a way i can avoid this by having spring.net automatically inject the singletons to a property i declare, like an array of ICustomInterfaceThatDoesSomething ? The only reason i want something like this is because i want to kill the

Asp.Net MVC Controller: declarative AOP with Spring.Net

爱⌒轻易说出口 提交于 2019-11-26 22:08:17
问题 Is it possible, that Spring.Net Aspects don't work with Asp.Net Controller? I want to configure transactions on Action methods of Controllers but the proxy doesn't seem to trigger. <object id="ControllerClassPointcut" type="Spring.Aop.Support.SdkRegularExpressionMethodPointcut, Spring.Aop"> <property name="patterns"> <list> <value>xxx.Controllers.CompanyController.*</value> </list> </property> </object> <aop:config> <aop:advisor pointcut-ref="ControllerClassPointcut" advice-ref="TxAdvice"/> <